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

[java]  view plain  copy
  1. @Controller  
  2. @RequestMapping("/value")  
  3. public class ValuePropertyController extends ApplicationController{  
  4.       
  5.     @Value("#{configProperties['jdbc.jdbcUrl']}")  
  6.     private String jdbcUrl;   
  7.       
  8.     @RequestMapping  
  9.     public String value(){  
  10.         System.out.println(jdbcUrl);  
  11.         return "";  
  12.     }  
  13. }  


applicationContext.xml

[html]  view plain  copy
  1. <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">  
  2.        <property name="locations">  
  3.            <list>  
  4.                <value>classpath:database.properties</value>  
  5.            </list>  
  6.        </property>  
  7.     </bean>  
  8.     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">  
  9.         <property name="properties" ref="configProperties" />  
  10.     </bean>  

database.properties

[html]  view plain  copy
  1. jdbc.jdbcUrl=jdbc:mysql://localhost:3306/commentDemo?useUnicode=true&characterEncoding=UTF-8  
全部评论

相关推荐

沟头学院:无关比赛不要写,这样会显着你主次不分,比赛不要撒谎,有哪些就写那些,创新创业建议删除。技能特长可以适当夸大。
点赞 评论 收藏
分享
菜鸡29号:根据已有信息能初步得出以下几点: 1、硕士排了大本和大专 2、要求会多语言要么是招人很挑剔要么就是干的活杂 3、给出校招薪资范围过于巨大,说明里面的薪资制度(包括涨薪)可能有大坑
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务