With Spring 3.1 and profiles, it becomes interesting to create a custom interface for defining specific profiles. Part of the beauty is the ability to completely forget the profile line name and just use annotation.
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Profile("Dev") public @interface Dev { }
And then just annotate beans with @Dev . This works great.
However, how to check if the @Dev profile is @Dev ? Environment.acceptsProfiles() requires a String argument. Is there a βneatβ way to do this, or is my only way to do something like:
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Profile(Dev.NAME) public @interface Dev { public static String NAME = "Dev"; } public class MyClass{ @Autowired private Environment env; private void myMethod(){ if( env.acceptsProfiles( Dev.NAME ) )
Despite the functionality, I do not really like this concept. Is there any other way to make this better?
source share