美文网首页
使用Spring 3的@value简化配置文件的读取

使用Spring 3的@value简化配置文件的读取

作者: printf200 | 来源:发表于2019-10-21 09:21 被阅读0次

Spring 3支持@value注解的方式获取properties文件中的配置值,大简化了读取配置文件的代码。

1、在springmvc.xml文件中配置properties文件

<context:property-placeholder location="classpath:app.properties"/>

2、在bean中使用@value注解获取配置文件的值

@Value("${chengmi_crawl_timer_enable}")
private Boolean timerEnabled;

即使给变量赋了初值也会以配置文件的值为准。

app.properties
chengmi_crawl_timer_enable=true

相关文章

网友评论

      本文标题:使用Spring 3的@value简化配置文件的读取

      本文链接:https://www.haomeiwen.com/subject/izmouctx.html