Can I replace Spring @Scope ("request") with JSR-330 @Scope?

Or can I associate a user interface implementation org.springframework.beans.factory.config.Scopewith a specific annotation @Scope?)?

For example, I configured a new type of scope:

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

class ConversationScope implements Scope { ... }

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

Now I want to use it as

@Component
@Conversation
class Topic { ... }

instead of <

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

Is it possible?

Is there something like "AnnotationPostProcessor" in spring-context?

+5
source share
1 answer

It seems to be possible by registering a custom scope with<context:component-scan>

For instance:

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

See also this example bridge for JSR-299 annotations if you need to tweak your solution a bit.

+8

All Articles