[color=red][b]1.创建config.propertites文件
[/b][/color]
[color=red][b]2.配置文件applicationContext.xml[/b][/color]
[color=red][b]3.java类中引用[/b][/color]
[/b][/color]
key=value
[color=red][b]2.配置文件applicationContext.xml[/b][/color]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.*"></context:component-scan>
<!-- 使用注解注入properties中的值 id=setting -->
<bean id="setting"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:*.properties</value>
</list>
</property>
<!-- 设置编码格式 -->
<property name="fileEncoding" value="UTF-8"></property>
</bean>
</beans>
[color=red][b]3.java类中引用[/b][/color]
// id=setting中找key的值
@Value("${key}")
private String key;