[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