您的位置:首页 > 产品设计 > UI/UE

@value注解使用的简单介绍 ---谷营中西

2016-07-08 11:18 417 查看
使用@value注解的时候格式:

@value需要参数

第一种方式:@Value(“#{configProperties[‘config.pageSize’]}”)

第二种方式:@Value(“${config.URl}”);

两种方式配置区别:

1、@Value(“#{configProperties[‘config.pageSize’]}”)这种形式的配置中有“configProperties”,其实它指定的是配置文件的加载对象:配置如下:

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


配置完就可完成对属性的具体注入了;

2、@Value("${config.pageSize}")这种形式不需要指定具体加载对象,这时候需要一个关键的对象来完成PreferencesPlaceholderConfigurer,这个对象的配置可以利用上面配置1中的配置,也可以自己直接自定配置文件路径。
如果使用配置1中的配置,可以写成如下情况:


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties"/>
</bean>


如果直接指定配置文件的话,可以写成如下情况:


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="location">
<value>config/config.properties</value>
</property>
</bean>


我常用配置就是使用注解:

使用注解 简单 快捷 粗暴 直达目的地。

使用方式介绍:

1.properties 配置文件



2.在配置文件中配置一下完事 见下图:



3.使用



完事儿。。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  value 谷营 wanzuwodu