Spring6+SpringSecurity6+JSF3.0部署Payara6报错及疑问
升级到JSF 3.0+Spring 6+Spring Security 6后Payara 6部署报错:缺少
mvcHandlerMappingIntrospector Bean 部署时出现如下错误日志:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList' with key [0] ...(省略中间栈信息) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mvcHandlerMappingIntrospector' available: A Bean named mvcHandlerMappingIntrospector of type org.springframework.web.servlet.handler.HandlerMappingIntrospector is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext. ...(省略中间栈信息)
核心错误为缺少名为mvcHandlerMappingIntrospector的Bean,项目相关配置文件如下:
securityJsfConfig.xml
<beans:beans > <beans:bean id="ajaxSessionManagementFilter" class="rpk.lincor.awp.filter.JsfAjaxFilter"> <beans:property name="invalidSessionUrl" value="/j_spring_security_logout" /> </beans:bean> <sec:http use-expressions="true" create-session="always" disable-url-rewriting="true"> <sec:intercept-url pattern="/modules" access="hasRole('ROLE_USER')" /> <sec:intercept-url pattern="/modules/pages/error.xhtml" access="permitAll" /> <sec:form-login login-page="/login.xhtml" username-parameter="j_username" password-parameter="j_password" login-processing-url="/j_spring_security_check" authentication-success-handler-ref="authSuccessHandler" authentication-failure-url="/login.xhtml?state=failure" /> <sec:logout logout-success-url="/login.xhtml?state=logout" logout-url="/j_spring_security_logout" invalidate-session="true" /> <sec:access-denied-handler ref="accessDeniedHandler" /> <sec:intercept-url pattern="/login.xhtml" access="! hasRole('ROLE_USER')" /> <sec:intercept-url pattern="/" access="! hasRole('ROLE_USER')" /> <sec:custom-filter ref="ajaxSessionManagementFilter" before="SESSION_MANAGEMENT_FILTER" /> <sec:csrf disabled="true"/> <sec:headers disabled="true"/> </sec:http> <sec:authentication-manager alias="authenticationManager"> <sec:authentication-provider ref="authProvider"> </sec:authentication-provider> </sec:authentication-manager> </beans:beans>
applicationContext.xml(部分内容)
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"\>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app > <display-name>ases</display-name> <context-param> <param-name>Version</param-name> <param-value>1.0.0.2</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/*.xml </param-value> </context-param> <context-param> <param-name>jakarta.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>jakarta.faces.FACELETS_LIBRARIES</param-name> <param-value>/WEB-INF/springsecurity.taglib.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <listener> <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class> </listener> <listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> <context-param> <param-name>jakarta.faces.PROJECT_STAGE</param-name> <param-value>Production</param-value> </context-param> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>pageFilter</filter-name> <filter-class>rpk.ases.awp.filter.PageServletFilter</filter-class> </filter> <filter-mapping> <filter-name>pageFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>validFilter</filter-name> <filter-class>rpk.lincor.awp.filter.ValidationFilter</filter-class> </filter> <filter-mapping> <filter-name>validFilter</filter-name> <url-pattern>/modules/pages/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>login.xhtml</welcome-file> </welcome-file-list> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>rpk.ases.awp.MyServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> <session-config> <session-timeout>60</session-timeout> </session-config> <error-page> <error-code>500</error-code> <location>/modules/pages/error.xhtml?code=500</location> </error-page> <error-page> <error-code>404</error-code> <location>/modules/pages/error.xhtml?code=404</location> </error-page> <error-page> <error-code>403</error-code> <location>/modules/pages/error.xhtml?code=403</location> </error-page> <error-page> <exception-type>java.io.FileNotFoundException</exception-type> <location>/modules/pages/error.xhtml?code=404</location> </error-page> <error-page> <exception-type>java.lang.ArrayIndexOutOfBoundsException</exception-type> <location>/modules/pages/error.xhtml?code=500</location> </error-page> <error-page> <exception-type>java.lang.IllegalArgumentException</exception-type> <location>/modules/pages/error.xhtml?code=500</location> </error-page> <error-page> <exception-type>jakarta.faces.application.ViewExpiredException</exception-type> <location>/modules/pages/error.xhtml?code=500</location> </error-page> <error-page> <exception-type>jakarta.servlet.ServletException</exception-type> <location>/modules/pages/error.xhtml?code=500</location> </error-page> </web-app>
applicationContext.xml与securityJsfConfig.xml均位于WEB-INF/spring目录下,此前使用JSF 2.3+Spring 5时一切正常,升级后出现该问题。
更新:
通过在applicationContext.xml中添加如下Bean解决了问题:
<bean id="mvcHandlerMappingIntrospector" class="org.springframework.web.servlet.handler.HandlerMappingIntrospector"> </bean>
不解为何新版本中必须手动配置该Bean,特此咨询。
内容的提问来源于stack exchange,提问作者san3k
相关产品推荐
相关产品推荐

