一:在工程中建立config.properties配置文件
[java] view plain copy
- #FTP的ip地址
- address=192.168.25.133
- #FTP的端口
- port=21
二:在spring配置文件中配置加载上述的资源文件。(两种方式)
方式1:s
[java] view plain copy
- <context:property-placeholder location="classpath:config/*.properties"/>
方式2;
[java] view plain copy
- <bean id="propertyBean"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <array>
- <value>classpath:config/*.properties</value>
- </array>
- </property>
- </bean>
三:使用配置文件中配置的值
[java] view plain copy
- @Value("${address}")
- private String ftpAddress;
这时ftp的地址直接就注入到ftpAddress中。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
一、spring(基础10) 注解@Value详解[1]
一 配置方式
@value需要参数,这里参数可以是两种形式:
[html] view plain copy
- @Value("#{configProperties['t1.msgname']}")或者@Value("${t1.msgname}");