Java Spring Security需要ContextLoaderListener,但需要I';我使用带注释的配置,怎么办?
我在为我的SpringWeb应用程序使用带注释的配置,然后不得不将XML与之混合,以便使用SpringSecurity。我用Java Spring Security需要ContextLoaderListener,但需要I';我使用带注释的配置,怎么办?,java,spring,spring-security,Java,Spring,Spring Security,我在为我的SpringWeb应用程序使用带注释的配置,然后不得不将XML与之混合,以便使用SpringSecurity。我用@ImportResource(“security config.xml”)注释了我的一个配置类,以加载安全配置。配置bean创建得很好。My web.xml看起来是这样的: springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilter
@ImportResource(“security config.xml”)
注释了我的一个配置类,以加载安全配置。配置bean创建得很好。My web.xml看起来是这样的:
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
字符编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
字符编码滤波器
/*
URL重写过滤器
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
对数电平
平民
confPath
/WEB-INF/conf/urlrewrite-config.xml
URL重写过滤器
/*
org.springframework.web.util.Log4jConfigListener
log4jConfigLocation
/WEB-INF/conf/log4j-config.xml
应用程序调度器
org.springframework.web.servlet.DispatcherServlet
上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
上下文配置位置
com.website.config
0
应用程序调度器
/应用程序/*
据我所知,springSecurityFilterChain需要ContextLoaderListener。但是,由于我的应用程序的配置方式,如果我添加:
org.springframework.web.context.ContextLoaderListener
对于my web.xml,我的应用程序未初始化。有没有办法在我的带注释的配置中手动创建ContextLoaderListener?我相信它可以与web app下的以下添加一起工作
上下文类
org.springframework.config.java.context.JavaConfigWebApplicationContext
上下文配置位置
com.website.config
来源:只需使用ContextLoaderListener创建一个根应用程序上下文
Spring配置文件。
上下文配置位置
/WEB-INF/spring/application.xml
Spring上下文侦听器。
org.springframework.web.context.ContextLoaderListener
在application.xml中,还可以定义基于注释的配置。它将由DispatcherServlet定义的WebApplicationContext继承
然后在application.xml中导入安全配置。因此,安全性将应用于配置中的所有ApplicationContexts。如果root.xml与web.xml目录不同,请不要忘记添加“classpath:/”。希望这对将来有帮助
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/appcontext-root.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
上下文配置位置
类路径:/appcontext-root.xml
org.springframework.web.context.ContextLoaderListener
照你说的做了,但我将“/WEB-INF/spring/application.xml”改为更具描述性的“/WEB-INF/conf/security config.xml”。谢谢你的帮助!如果我不想使用xml文件,只想使用注释,有没有办法注册spring listener类?您是否尝试过JavaConfigWebApplicationContext方法?它也应该起作用。