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

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

<bean id="appProperty"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <array>
            <value>classpath:app.properties</value>
        </array>
    </property>
</bean>

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

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

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

相关文章:

  • 2021-07-03
  • 2021-04-10
  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2021-10-14
  • 2021-09-30
  • 2022-12-23
  • 2022-03-06
相关资源
相似解决方案