java Spring security 3.0.3 配置错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3721513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 03:09:39  来源:igfitidea点击:

Spring security 3.0.3 configuration error

javaspringtomcatconfigurationspring-security

提问by Mark Baijens

I'm trying to implement spring-security to handle authentication and authorization of my web application. I can't get the configuration right. Tomcat trows an error when I deploy the war file.

我正在尝试实现 spring-security 来处理我的 Web 应用程序的身份验证和授权。我无法正确配置。当我部署 war 文件时,Tomcat 会出现错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] while setting bean property 'parent'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException

I got the following configuration.

我得到了以下配置。

WEB-INF/spring/web-application-context.xml

WEB-INF/spring/web-application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.0.3.xsd">

    <http auto-config='true'>
        <intercept-url pattern="/index.html*" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <intercept-url pattern="/index.jsp*" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <form-login login-page='/jsp/loginform.jsp'/>
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" />
                <user name="bob" password="bobspassword" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

WEB-INF/web.xml

WEB-INF/web.xml

<listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>

  <context-param>
    <param-name>contextConfigLocation</param-name>
      <param-value>
        /WEB-INF/spring/web-application-context.xml
      </param-value>
  </context-param>


  <filter>
    <filter-name>myFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>myFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

回答by axtavt

Exception message clearly says that class org.springframework.dao.DataAccessExceptionis missing, therefore you need to add org.springframework.transaction-*.jarto the classpath (i.e. to /WEB-INF/lib).

异常消息清楚地表明该类org.springframework.dao.DataAccessException丢失,因此您需要添加org.springframework.transaction-*.jar到类路径(即 to /WEB-INF/lib)。