// application.properties (You can override with other VM or environment variables) app.name=JohnDoe app.greeting=Hello!!! // ApplicationConfig.java @Configuration @PropertySource("classpath:application.properties") public class ApplicationConfig { @Value("${app.greeting}") private String greeting; @Value("${app.name}") private String name; // Setting up the is24 SPEL variable to replace different profile beans @Value("#{new Boolean(environment['spring.profiles.active']!='dev')}") private boolean is24; @Autowired private GreetingService greetingService; @Autowired private TimeService timeService; // One Bean to replace multiple beans of different profiles with SPEL variable is24 @Bean public TimeService timeService(){ return new TimeService(is24); } // @Bean // @Profile("!dev") // public TimeService timeService(){ // return new TimeService(true); // } // // @Bean // @Profile("dev") // another bean configuration for different profile // public TimeService timeService12(){ // return new TimeService(false); // } @Bean public GreetingService greetingService(){ return new GreetingService(greeting); } @Bean public OutputService outputService(){ return new OutputService(greetingService, timeService, name); } } // Application.java public class Application { public static void main(String[] args) throws Exception { ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class); OutputService outputService = context.getBean(OutputService.class); for (int i=0;i<5;i++){ outputService.generateOutput(); Thread.sleep(5000); } } }