gpt4 book ai didi

java - Spring项目找不到springSecurityFilterChain

转载 作者:行者123 更新时间:2023-12-02 05:17:59 28 4
gpt4 key购买 nike

尝试在您的项目中实现 springowego Spring Security,但我遇到了问题。当我尝试运行一个项目时,错误使我崩溃:

lis 05, 2014 2:54:51 PM org.apache.catalina.core.StandardContext filterStart SEVERE: Exception starting filter springSecurityFilterChain org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097) at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326) at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:236) at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:194) at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262) at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:107) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

lis 05, 2014 2:54:51 PM org.apache.catalina.core.StandardContext startInternal 严重:过滤器错误开始时间 2014 年 05 月 2:54:51 PM org.apache.catalina.core.StandardContext startInternal 严重:上下文 [/ibank] 由于之前的错误,启动失败

我的 web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>

</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-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>

</web-app>

安全配置.xml:

    <beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" 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-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">

<http auto-config="true">
<access-denied-handler error-page="/403page" />
<intercept-url pattern="/client**" access="ROLE_CLIENT" />
<intercept-url pattern="/admin**" access="ROLE_ADMIN" />
<form-login login-page='/login' username-parameter="username"
password-parameter="password" default-target-url="/user"
authentication-failure-url="/login?authfailed" />
<logout logout-success-url="/login?logout" />
</http>

<!-- <authentication-manager> <authentication-provider> <user-service> <user
name="user" password="user@123" authorities="ROLE_ADMIN" /> </user-service>
</authentication-provider> </authentication-manager> -->

<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select username,password, enabled from users where username=?"
authorities-by-username-query="select username, role from user_roles where username =? " />
</authentication-provider>
</authentication-manager>

</beans:beans>

我找到了这个主题,但我现在不知道他是如何解决的 Spring : Exception starting filter springSecurityFilterChain

我试试

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/security-config.xml
</param-value>
</context-param>

但是应用程序仍然无法正常工作,并且出现以下错误:

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security] Offending resource: ServletContext resource [/WEB-INF/spring/security-config.xml]

lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security] Offending resource: ServletContext resource [/WEB-INF/spring/security-config.xml]

lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [/ibank] startup failed due to previous errors lis 05, 2014 3:28:37 PM org.apache.catalina.core.ApplicationContext log INFO: Closing Spring root WebApplicationContext lis 05, 2014 3:28:37 PM org.apache.catalina.core.StandardContext listenerStop SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

警告:org.springframework.web.context.support.XmlWebApplicationContext - ApplicationListener 处理 ContextClosedEvent 引发异常 java.lang.IllegalStateException:ApplicationEventMulticaster 未初始化 - 在通过上下文多播事件之前调用“刷新”:根 WebApplicationContext:启动日期 [2014 年 11 月 5 日星期三 15:28:35 CET];上下文层次结构的根

警告:org.springframework.web.context.support.XmlWebApplicationContext - 上下文关闭时从 LifecycleProcessor 抛出异常 java.lang.IllegalStateException:LifecycleProcessor 未初始化 - 在通过上下文调用生命周期方法之前调用“刷新”:Root WebApplicationContext:启动日期 [CET 2014 年 11 月 5 日星期三 15:28:35];上下文层次结构的根

最佳答案

你的 web.xml 说

   <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

除非您的 root-context.xml 包含 security-config.xml,否则您必须在那里列出它

   <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/security-config.xml
</param-value>
</context-param>

根据您的最新更新,我相信您的问题有两个方面,一是不包括安全配置,二是缺少 pom 属性,请尝试添加

 <spring.security.version>3.1.0.RELEASE</spring.security.version>

在您的属性部分中。版本可能不适合您,但问题应该得到解决

关于java - Spring项目找不到springSecurityFilterChain,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26758932/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com