一种方式是将一批资源文件交由spring管理,在类中以@Value的方式直接提取信息。
classpath目录下创建xxx.properties文件
applicationContext.xml中配置
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath*:xxx.properties</value>
...
</list>
</property>
</bean>
java类
...
import org.springframework.beans.factory.annotation.Value;
...
@Value("${properties文件中的key}")
private String abc;
现在可以直接使用abc属性了。
一种方式是定义一个properties文件bean,再注入到类中,使用时通过properties.getProperty()来提取信息。
classpath目录下创建xxx.properties文件
applicationContext.xml中配置
...
xmlns:util="http://www.springframework.org/schema/util"
...
<util:properties id="property_a" location="classpath:openview-jms.properties"/>
...
java类
...
import org.springframework.beans.factory.annotation.Autowired;
...
@Autowired
private Properties property_a;
...
现在可以用openview_jms.getProperty("properties文件中的key")提取信息了。
classpath目录下创建xxx.properties文件
applicationContext.xml中配置
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath*:xxx.properties</value>
...
</list>
</property>
</bean>
java类
...
import org.springframework.beans.factory.annotation.Value;
...
@Value("${properties文件中的key}")
private String abc;
现在可以直接使用abc属性了。
一种方式是定义一个properties文件bean,再注入到类中,使用时通过properties.getProperty()来提取信息。
classpath目录下创建xxx.properties文件
applicationContext.xml中配置
...
xmlns:util="http://www.springframework.org/schema/util"
...
<util:properties id="property_a" location="classpath:openview-jms.properties"/>
...
java类
...
import org.springframework.beans.factory.annotation.Autowired;
...
@Autowired
private Properties property_a;
...
现在可以用openview_jms.getProperty("properties文件中的key")提取信息了。