美文网首页
sprng通过@Value注解读取.properties配置内容

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

作者: 崔可仁 | 来源:发表于2020-03-11 21:50 被阅读0次

@Controller  

@RequestMapping("/value")  

public class ValuePropertyController extends ApplicationController{  

@Value("#{configProperties['jdbc.jdbcUrl']}")  

private String jdbcUrl;   

@RequestMapping  

public 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

相关文章

网友评论

      本文标题:sprng通过@Value注解读取.properties配置内容

      本文链接:https://www.haomeiwen.com/subject/nmalyctx.html