5

org.springframework.beans.factory.config.Scope或者,我可以使用特定的带@Scope注释的注释来绑定接口的自定义实现吗?

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

@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”的东西?

4

1 回答 1

8

似乎可以通过您的<context:component-scan>

例如:

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

如果您需要更多地定制您的解决方案,另请参阅此JSR-299 注释桥接示例。

于 2011-03-21T20:09:53.227 回答