您的位置:首页 > 产品设计 > UI/UE

通过@Value注解读取.properties配置内容

2017-06-11 10:15 323 查看
方案一:

    applicationContext-dao.xml中添加

      <!-- 加载配置文件 -->

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

         <property name="locations">

             <list>

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

             </list>

         </property>

      </bean>

      <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">

           <property name="properties" ref="configProperties" />

       </bean>

       Service、Controller层调用代码:

       @Value("#{configProperties['jdbc.url']}")
        private String url;

方案二:

       applicationContext-dao.xml、springmvc.xml中添加

       <!-- 加载配置文件 -->

       <context:property-placeholder location="classpath:properties/*.properties" />

       Service、Controller层调用代码:

       @Value("${jdbc.url}")
  private String url;

      

      

       
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息