I have a Spring Boot application with several Java Config classes. Each class has its own @Profile
name. When running the application from Eclipse with the Program Arguments set to --spring.profiles.active=config1,config2
the server runs as expected with all beans from both Config classes running.
But when I try to start the application from the command line with --spring.profiles...
only one of the profiles' beans are running, and the order doesn't matter. It is only the alphabetically last profile that is running. Even though the log says
The following profiles are active: config1,config2
Still none of the beans from config1
is kicking in.
Also tried to set spring.profiles.include
in the props file with the same result.
Any ideas?
This problem still puzzles me. If any profile is used isolated they work, but when these two are combined the config1
profile's beans are never created. Debugging the Spring startup says that the config is found and the pre-creation is happening. But the real beans are never created and returned.
I made a wrapper class that wraps one of the beans in the config1
Java Config class to force Spring to create the beans from that particular config. This is not the answer nor a solution to the problem but a work around.
@Service
@Profile("config1")
public class DataConsumerWrapperService {
public DataConsumerWrapperService(final MessageParser mp) {
// Do nothing, just trigger the parser bean creation
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.