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

来源:互联网 发布:mysql in用什么取代 编辑:程序博客网 时间:2024/05/29 04:51
@Controller@RequestMapping("/value")public class ValuePropertyController extends ApplicationController{    @Value("#{configProperties['jdbc.jdbcUrl']}")private String jdbcUrl; @RequestMappingpublic String value(){System.out.println(jdbcUrl);return "";}}

applicationContext.xml


<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">       <property name="locations">           <list>               <value>classpath:database.properties</value>           </list>       </property>    </bean>    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">        <property name="properties" ref="configProperties" />    </bean>

database.properties


jdbc.jdbcUrl=jdbc:mysql://localhost:3306/commentDemo?useUnicode=true&characterEncoding=UTF-8  


0 0