您的位置:首页 > 编程语言 > Java开发

springboot xml配置,properties配置,profile配置

2017-01-13 00:00 531 查看
摘要: springboot xml配置,properties配置

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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  springboot