码上敲享录 > java入门知识分享 > spring使用注解注入properties中的值的简单示例

spring使用注解注入properties中的值的简单示例

上一章章节目录下一章 2017-09-03已有2051人阅读 评论(0)

使用注解注入properties中的值的简单示例


1.在web项目的src目录下新建setting.properties的文件,内容如下:

version=1


2.在spring的xml配置文件中加入以下配置:

<!-- 使用注解注入properties中的值 -->

   <bean id="setting" class="org.springframework.beans.factory.config.PropertiesFactoryBean">

       <property name="locations">

           <list>

               <value>classpath:setting.properties</value>

           </list>

       </property>

       <!-- 设置编码格式 -->

       <property name="fileEncoding" value="UTF-8"></property>

   </bean>


3.在controller类中加入以下注解即可

  @Value("#{setting[version]}")

   private String version;


向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交