Is it possible to replace Spring @Scope("request") with JSR-330 @Scope variant?
Asked Answered
H

1

5

Or, can I bound a custom implementation of org.springframework.beans.factory.config.Scope interface with a specific @Scope-annotated annotation?

For example, I have customized a new scope type:

@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?

Hobbism answered 21/3, 2011 at 15:58 Comment(1)
If it doesn't work out of the box with <context:annotation-driven/> or <context:component-scan/>, then it likely won't work at all.Rigorous
C
8

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

For example:

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

See also this example of a bridge for JSR-299 annotations if you need to customize your solution a little bit more.

Clay answered 21/3, 2011 at 20:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.