For future readers who don’t want to have multiple @Beans
annotated with @Profile
, this could also be a solution:
class MyService {
@Autowired
Environment env;
void run() {
if (Arrays.asList(env.getActiveProfiles()).contains("dev")) {
log();
}
}
void log() {
//only during dev
}
}