spring 使用注解获取properties 文件属性值

来源:互联网 发布:单片机智能车 编辑:程序博客网 时间:2024/05/22 10:31

1.配置bean   截取片段

<!-- 引入配置文件 --><bean id="configProperties"class="org.springframework.beans.factory.config.PropertiesFactoryBean"><property name="locations"><list><value>classpath:application.properties</value></list></property></bean><bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"><property name="properties" ref="configProperties" /></bean>


2.properties 的配置

#资讯网站配置web.catch.url=first.name=hering

3.java 代码中获取属性值的配置 不需要使用set get 方法,好像还有一种使用get set 方式的。待我研究一下怎么使用,再写出来。

@Value("#{configProperties['first.name']}")private String myname;

4.测试结果

@RequestMapping("getinfo")@ResponseBodypublic WebJson getInfo(@RequestParam (value="id",required=true)Integer id){WebJson json=new WebJson();System.err.println(myname+"-------");//Assert.notNull(info,"【getInfo】系统无法查询到id="+id+"的资讯");return json;}


Hibernate: select infomation0_.id as id1_0_, infomation0_.author as author2_0_, infomation0_.content as content3_0_, infomation0_.created as created4_0_, infomation0_.source as source5_0_, infomation0_.summary as summary6_0_, infomation0_.title as title7_0_ from infomation infomation0_ where infomation0_.id=?
hering-------

0 0
原创粉丝点击