配置文件
application.properties
1 | = haha |
1. @Value
1 |
|
2. @ConfigurationProperties读取配置文件并与 bean 绑定
创建一个MessageProperties类,在该类上加了 @Component 注解,我们可以像使用普通 bean 一样将其注入到类中使用。
1 |
|
使用时,注入刚才注册的bean
1 |
|
3. @ConfigurationProperties读取配置文件,但不与bean 绑定
1 |
|
使用时,在要使用MessageProperties的地方使用@EnableConfigurationProperties注解注册我们的配置bean
1 |
|