Spring MVC @Controller and profiles
Asked Answered
D

1

17

I have a spring mvc controller and I want to enable it only in some profiles (for example development and test).

I know I can use the profile attribute of the beans element in xml configuration to limit the scope of my beans, but I'm using convenient annotations for the controllers now.

Can I bind the annotated controller to given profile somehow?

Or do I have to use the "old way" (of implementing and declaring controller) without annotations and use the beans element in xml configuration?

Will the annotated controllers mix well with the "old ones"?

EDIT: another way, which comes to my mind, is to check the profile in runtime from autowired Environment instance, but this denies the inversion of control

Dahlgren answered 12/6, 2013 at 13:58 Comment(4)
Put a different <component-scan> inside a profile <beans profile="dev">.Catalan
Theres an @Profile annotation ?Sudan
@Sudan Is that a question or are you telling him there is such an annotation?Catalan
There is such an annotation.Sudan
S
24

Is this what you mean ?

@Controller
@Profile("test")
public class CacheController {
}

javadoc

Sudan answered 12/6, 2013 at 14:3 Comment(3)
Here's javadoc.Catalan
I should RTFM more carefully next time, I thought that the Profile annotation is only useful in java based configuration and not with the beans.Dahlgren
Using the right import is also important, because org.opengis.annotation.Profile for example is also a type annotation.Colenecoleopteran

© 2022 - 2024 — McMap. All rights reserved.