spring Controller 层注解获取 properties 里面的值

时间:2023-03-09 08:12:29
spring Controller 层注解获取 properties 里面的值

前言:最近在做一个项目,想要在 controller 层直接通过注解 @Value("")来获取 properties 里面配置的属性。

  这个其实和 springmvc、spring 两个容器相关。controller 是在 springmvc 容器中,所以需要看看 springmvc 的配置文件中是否有配置 properties 文件。

  经设置,即可在 controller 层使用 @Value 了。

    <!-- 加载配置文件,controller中需要使用@Value得到配置值 -->
<context:property-placeholder location="classpath*:conf/system/*.properties"/>

  参考:http://www.cnblogs.com/hafiz/p/5875740.html