Java – method level spring configuration file?
I want to introduce some methods that are only implemented in the development process
I thought I could use the spring @ profile annotation here? However, how do you apply this annotation at the class level so that this method is called only when a specific profile is configured in the property?
spring.profiles.active=dev
Use the following as pseudocode How can this be done?
class MyService { void run() { log(); } @Profile("dev") void log() { //only during dev } }
Solution
As can be in http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/context/annotation/Profile.html Read on
So, a @ profile annotation in a class, all methods and imports No class
What you want to do may be by making two classes implement the same interface and injecting one or another class according to the configuration file Look at the answer to this question
Annotation-driven dependency injection which handles different environments