I am working on a spring boot application.i am using spring boot version: 2.2.4-RELEASE
I am trying to create a bean specific for a profile.but the bean is not creating as expected.
Below is my configuration file:
@Configuration
@Slf4j
public class TestConfig {
//below is the bean i need to be created for dev and test
@Bean
@Profile({“dev”, “test”})
TestObject getTestObject() {
//do something
}
//below is the bean i need to be created for staging and prod
@Bean
@Profile({“staging”, “prod”})
TestObject getTestObject() {
//do something
}
//someother beans common for all profiles
}
Service.java
@Service
public class Serviceclass {
@Autowired
private TestObject testObj;
//some methods
}
I tried the above way, but the bean is Not getting created for any of the profiles. Any suggestions on how to achieve this would be helpful.
Update: the application is failing to start as one of the service class has dependency on the bean i am trying to create.
Thanks in advance.