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

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

【Spring】13、使用Spring 3的@value简化配置文件的读取
<context:property-placeholder location="classpath:fuyou.properties"/>
【Spring】13、使用Spring 3的@value简化配置文件的读取

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

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

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

 

需要注意的是:如果没有带入

properties配置文件,启动的时候会报 Could not resolve placeholder 的错误。

相关文章:

  • 2021-07-12
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
猜你喜欢
  • 2021-10-07
  • 2022-12-23
  • 2021-06-01
  • 2021-11-13
  • 2022-12-23
  • 2021-12-13
  • 2022-01-24
相关资源
相似解决方案