或者,我可以将 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/