引用:property-placeholder/override
读取property文件的方式
Context
1 | <!--注解支持--> |
这里component-scan
中包含两个属性,一个是exclude-filter
不包含include-filter
包含
里面的type
属性对应有四种
annotation
表示过滤方式为注解,含有后面expression注解的都会被过滤掉
expression示例:cn.ws.annotation.AccessCheck
regex
以正则表达式的方式过滤
expression示例:com.\ws\..*assignable
以继承和实现的方式过滤,所有继承或者实现了后面expression的都会被过滤
expression示例:java.util.HashMap
aspectj
以Aspectj表达式的方式过滤
expression示例:custom
自定义TypeFilter过滤规则,写一个类,这个类必须实现org.springframework.core.type.TypeFilter
接口
expression示例:cn.ws.MyTypeFilter
1
2<context:property-override file-encoding="utf-8" ignore-unresolvable="true" location="classpath:spring/test.properties"/>
<context:property-placeholder location="classpath:spring/test.properties" file-encoding="utf-8" ignore-unresolvable="true"/>property-placeholder
可以读取properties文件
另外通过下面的方式也可以读取1
2
3
4
5
6
7
8
9<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:test.properties</value>
<value>classpath:test1.properties</value>
</list>
</property>
</bean>
注意:这种方式下,如果你在spring-mvc.xml文件中有如下配置,则一定不能缺少下面的红色部分,原因
详细参考:spring获取property