java - 是否可以用 JSR-330 @Scope 变体替换 Spring @Scope ("request")?

标签 java spring jsr330

或者,我可以将 org.springframework.beans.factory.config.Scope 接口(interface)的自定义实现与特定的 @Scope 注释绑定(bind)吗?

比如我自定义了一个新的作用域类型:

@javax.inject.Scope @Retention(RUNTIME)
@interface Conversation {}

class ConversationScope implements Scope { ... }

class ConversationScopeConfigurer extends BeanFactoryPostProcessor
    { beanFactory.registerScope("conversation", new ConversationScope()); }

现在我想用它作为,

@Component
@Conversation
class Topic { ... }

而不是,

@Component
@org.springframework.context.annotation.Scope("conversation")
class Topic { ... }

这可能吗?

spring-context 中有类似“AnnotationPostProcessor”的东西吗?

最佳答案

注册一个custom scope resolver似乎是可能的用你的<context:component-scan>

例如:

<context:component-scan base-package="com.company" scope-resolver="org.springframework.context.annotation.Jsr330ScopeMetadataResolver" />

另请参阅 bridge for JSR-299 annotations 的示例如果您需要更多地自定义您的解决方案。

关于java - 是否可以用 JSR-330 @Scope 变体替换 Spring @Scope ("request")?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5380235/

相关文章:

java - 如何在android库gradle项目中包含依赖项?

java - 象夫 : Cannot convert into sequence file

java - Spring MVC 是否缓存在 Web 应用程序启动时未加载的 bean 文件?

java - 如何在每个特定时间间隔调用 Spring Controller ?

java - 直接支持JSR-330注入(inject)的嵌入式web容器?

java - Lab颜色空间中的颜色梯度算法

java - Guava 缓存并保留已检查的异常

spring - 哪个版本的spring支持open jdk或反之请确认

java - 单元测试 JSR-330 注入(inject)对象