欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

@Value 注解获取properties值

发布时间:2025/4/14 35 豆豆
生活随笔 收集整理的这篇文章主要介绍了 @Value 注解获取properties值 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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

 

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;

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

转载于:https://www.cnblogs.com/drizzlewithwind/p/5721337.html

总结

以上是生活随笔为你收集整理的@Value 注解获取properties值的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。