我正在使用Spring 4.我的配置是:
的web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:contexts/root/spring-root-context.xml
classpath:contexts/security/security-context.xml</param-value>
</context-param>
弹簧根context.xml中
<context:property-placeholder location="classpath:credentials.properties" />
安全context.xml中
<beans:bean id="myCustomFilter" class="filters.MyCustomFilter">
<beans:property name="authenticationManager" ref="authenticationManager" />
</beans:bean>
credentials.properties
ClientSecret = QWERTY
MyCustomFilter.java
public class MyCustomFilter extends AbstractAuthenticationProcessingFilter {
@Value("${ClientSecret}")
private String clientSecret;
}
已加载属性文件
INFO RMI TCP Connection(3)-127.0.0.1 support.PropertySourcesPlaceholderConfigurer:172 - Loading properties file from class path resource [credentials.properties]
未注入clientSecret的值。
答案 0 :(得分:1)
您的<context:annotation-config>
似乎没有spring-root-context.xml
。
从另一方面来说,如果您将MyCustomFilter
配置为<bean>
,只需使用它的属性:
<beans:bean id="myCustomFilter" class="filters.MyCustomFilter">
<beans:property name="authenticationManager" ref="authenticationManager" />
<beans:property name="clientSecret" value="${ClientSecret}" />
</beans:bean>
如果你有setter
,那当然。