1.使用xml配置
@InportResource加载xml
例:@InportResource({"classpath:some-XXXXX.xml","classpath:another-XXXXX.xml"})
2.常规属性配置
application.properties 中添加的属性
使用注解@Value{}
3.类型安全的配置(基于properties)
通过@ConfigurationProperties讲properties和bean进行关联。
例:
aaa.propeties
book.name=zhangsan
book.price=50
@Component
@ConfigurationProperties(prefix="book",location={"classpath:aaa.properties"})
public class Book(){
private String name;
private String price;
setter getter....
}
4.profile配置
profile是spring用来针对不同环境对不同配置进行的支持,全局profile使用application-{profile}.properties,在application.properties中设置spring.profile.active=XXX来制定profile。
本文详细介绍了Spring框架中的四种配置方式:XML配置、常规属性配置、类型安全的配置及profile配置,并提供了具体的实现示例。
1132

被折叠的 条评论
为什么被折叠?



