文章标题
来源:互联网 发布:php 使用ftp上传文件 编辑:程序博客网 时间:2024/06/07 20:29
通过@Value注解读取.properties配置内容
- @Controller
- @RequestMapping(“/value”)
- public class ValuePropertyController extends ApplicationController{
- @Value(“#{configProperties[‘jdbc.jdbcUrl’]}”)
- private String jdbcUrl;
- @RequestMapping
- public String value(){
- System.out.println(jdbcUrl);
- return “”;
- }
- }
@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>
<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
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/commentDemo?useUnicode=true&characterEncoding=UTF-8
</article>
阅读全文
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- Viewpager 嵌套fragment的问题
- jacoco的maven插件使用
- python自定义模块
- thinkphp新的类和方法不能访问
- TF-slim快速搭建cnn
- 文章标题
- texworks editor & previewer 已停止工作
- 如何处理前任程序员留下的代码
- 回调同名导致java.lang.StackOverflowError错误
- Jcoco的简单使用介绍
- 10月30日云栖精选夜读:云栖大会Serverless场分享:日志处理挑战与展望
- 数据结构实验之二叉树七:叶子问题
- PHPstorm中bootstrap3插件中cdn问题与thinkPHP中引入bootstrap笔记
- Android Fillder工具网络监测