I'm new to spring and I'm studying it. And stumbled upon the @Profile annotation.
I want to write a simple project with Spring (not Springboot) to learn how to load properties based on the environment using @profile annotation. Almost everywhere, the examples (Ex1, Ex2) I see only with the Springboot. I'm wondering whether we cannot write a Spring application that can dynamically load the properties based on the environment (dev, prod).
Some examples ( Ex3, Ex4, Ex5) show with the @Profile but those have hardcoded the bean details for each environment like below. Is this how we have to write the property loading?
@Profile("dev") @Bean public String devDBCcnnection() { System.out.println(dbConfiguration.getUrl()); return "DB Connection for Dev"; } @Profile("test") @Bean public String devTestCcnnection() { System.out.println(dbConfiguration.getDriverClassName()); return "DB Connection for Test"; } @Profile("prod") @Bean public String devProdCcnnection() { System.out.println("DB Connection for Prod"); return "DB Connection for Prod"; }
It has to write a bean for each profile like in the above example?
Can someone tell me using @Profiles, can't dynamically load the property values like in Spring applications?
Appreciate it if you can give the samples with Spring 5