The approach to loading yaml, IMHO properties can be done in two ways:
but. You can put the configuration in the standard location - application.yml in the root directory of the path - usually src/main/resources , and this yaml property should automatically load when you boot Spring with the name of the smoothed path you specified.
b. The second approach is a bit more extensive, basically defining a class for storing your properties as follows:
@ConfigurationProperties(path="classpath:/appprops.yml", name="db") public class DbProperties { private String url; private String username; private String password; ... }
Essentially, this suggests that it loads the yaml file and populates the DbProperties class based on the root db element.
Now, to use it in any class, you will need to do this:
@EnableConfigurationProperties(DbProperties.class) public class PropertiesUsingService { @Autowired private DbProperties dbProperties; }
Any of these approaches should work for you using Spring-boot.
Biju Kunjummen Jan 22 '14 at 1:36 on 2014-01-22 01:36
source share