원래 답변
필터는 ContextLoaderListener에에서로드의 ApplicationContext를 사용하기 때문에 필터에 <init-param>
이 사용되지 않습니다. 대신 ContextLoaderListener에 대한 프로필을 활성화하는 방법 중 하나를 사용하려고합니다.
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>secured</param-value>
</context-param>
후속
을 코멘트에 따라 최대 다음은 아래 그림과 같이 한 가지 방법은을 사용하는 것입니다. web.xml은 언제나 DelegatingFilterProxy를 항상로드하므로 Spring 프로필을 사용하여 필터를 생략 할 수 없습니다. DelegatingFilterProxy는 항상 대리자를로드하려고 시도합니다. 위임자가 누락되면 오류가 발생합니다. 아래 그림과 같이 대신 봄 보안을 사용하지 않도록 설정 프로파일을 만들 수 있습니다
<b:beans profile="default,secured">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user" password="password" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</b:beans>
<b:beans profile="insecure">
<http security="none" />
</b:beans>
그런 다음 아래 그림과 같이 web.xml의 불안 프로파일을 활성화하여 봄 보안을 해제 할 수있다. 당신이 봄 보안을 사용하지 않는 경우
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>insecure</param-value>
</context-param>
당신은 아무것도하지 않는 필터를 생성하여 필터를 해제하지만, FilterChain에게 장애인 프로필에 있다는 배치를 계속할 수 있습니다. 예 :
public class DoFilterChainFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
public void destroy() { }
public void init(FilterConfig filterConfig) throws ServletException { }
}
감사합니다. 그래서 특정 프로파일에서만 필터를 인스턴스화 할 수 없습니까? – MikePatel
나는 그 질문을 이해하고 있는지 확신 할 수 없다. 프로필은 전체 구성에 영향을 미치지 만 필터에 대한 프로필 만 사용하여 필터에만 영향을 줄 수 있습니다. –
네, 그렇지만 프로필에서 필터를 인스턴스화할지 여부를 결정해야한다고 생각합니다. – MikePatel