Spring安全性无法解析对bean

时间:2015-05-04 19:59:00

标签: jsf spring-security

在尝试部署集成了spring security的jsf项目时,我收到了以下错误。我刚刚开始使用Spring安全性,因为带有安全领域的java ee安全性太麻烦了。我看了this tutorial。所以我不确定这个错误到底意味着什么。我今天也开始学习,所以我把我放在那里的依赖项包括在内以防万一。

(我将错误作为引用放在页面底部)。

cannot Deploy InscriptionTemp2 deploy is failing=Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: 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#1' while setting bean property 'sourceList' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#1': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [6]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': 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 constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.security.provisioning.JdbcUserDetailsManager] for bean with name 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/core/support/JdbcDaoSupport. Please see server.log for more details.

的applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:sec="http://www.springframework.org/schema/security"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
          http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

    <!-- begin Spring Security config -->
    <sec:global-method-security secured-annotations="enabled" />

    <!-- Don't SSL encrypt static resources -->
    <sec:http pattern="/resources/**" security="none"/>

    <sec:http auto-config="true" >

        <!-- On Glassfish, dev ports are 8080 and 8181, whereas on
        production its 80 and 443 -->
        <sec:port-mappings>
            <sec:port-mapping http="8080" https="8181"/>
        </sec:port-mappings>

        <sec:intercept-url 
            pattern="/faces/restricted/user/**" 
            access="ROLE_ADMIN, ROLE_ADMIN" requires-channel="https" />
        <sec:intercept-url 
            pattern="/faces/restricted/admins/**" 
            access="ROLE_ADMIN" requires-channel="https" />
        <sec:intercept-url 
            pattern="/**" 
            access="IS_AUTHENTICATED_ANONYMOUSLY"/>

        <!-- Use O/S provided login window
        <http-basic />
        -->
        <!-- Use custom form for login -->
        <sec:form-login 
            login-processing-url="/j_spring_security_check"
            login-page="/faces/login.xhtml" 
            authentication-success-handler-ref="myAuthenticationHandler"
            authentication-failure-url="/faces/loginerror.xhtml"/>

        <sec:logout logout-url="/j_spring_security_logout" 
                    invalidate-session="true" 
                    logout-success-url="/faces/index.xhtml" />

    </sec:http>

    <sec:authentication-manager alias="authenticationManager">
        <sec:authentication-provider>
            <sec:password-encoder ref="encoderBean">
                <sec:salt-source user-property="username"/>
            </sec:password-encoder>
            <sec:jdbc-user-service data-source-ref="dataSource" /> 

            <!-- if not using a database for accounts, hard-code them here
           <sec:user-service>
               <sec:user name="admin" password="admin" authorities="ROLE_ADMIN, ROLE_MEMBER" />
               <sec:user name="member" password="member" authorities="ROLE_MEMBER" />
           </sec:user-service>
            -->
        </sec:authentication-provider>
    </sec:authentication-manager>

    <bean id="myAuthenticationHandler" class="com.activee.utils.MyAuthenticationHandler" />

    <bean id="encoderBean" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
        <constructor-arg value="512" />
        <property name="iterations" value="1024"/>
    </bean>


    <!-- Server managed connection pool accessed via JNDI -->
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/inscriptiontestDS"/>

</beans>

我的gradle依赖项:

dependencies {
    compile 'org.springframework.security:spring-security-web:4.0.1.RELEASE'
    compile 'org.springframework.security:spring-security-config:4.0.1.RELEASE'
    compile 'org.springframework.security:spring-security-core:4.0.1.RELEASE'    
}

我的web.xml

 <!-- Security configuration
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>  -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <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>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    <!-- end spring configuration -->

并且按照您的最大荣幸承诺,错误如引用:

  

无法部署InscriptionTemp2部署失败=期间发生错误   部署:加载应用程序时出现异常:   java.lang.IllegalStateException:ContainerBase.addChild:start:   org.apache.catalina.LifecycleException:   org.springframework.beans.factory.BeanCreationException:错误   使用名称&#39; org.springframework.security.filterChains&#39;创建bean:   无法解析对bean的引用   &#39; org.springframework.security.web.DefaultSecurityFilterChain#1&#39;而   设置bean属性&#39; sourceList&#39;用键1;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.security.web.DefaultSecurityFilterChain#1&#39 ;:   无法解析对bean的引用   &#39; org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0&#39;   用key [6]设置构造函数参数;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0&#39 ;:   无法解析对bean的引用   &#39; org.springframework.security.authentication.ProviderManager#0&#39;而   设置bean属性&#39; authenticationManager&#39 ;;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.security.authentication.ProviderManager#0&#39 ;:   无法解析对bean的引用   &#39; org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0&#39;   设置构造函数参数时;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0&#39 ;:   FactoryBean在对象创建时抛出异常;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.security.authenticationManager&#39;:无法解决   引用bean   &#39; org.springframework.security.authentication.dao.DaoAuthenticationProvider#0&#39;   用key [0]设置构造函数参数;嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.security.authentication.dao.DaoAuthenticationProvider#0&#39 ;:   无法解析对bean的引用   &#39; org.springframework.security.provisioning.JdbcUserDetailsManager#0&#39;   设置bean属性&#39; userDetailsS​​ervice&#39 ;;嵌套异常是   org.springframework.beans.factory.CannotLoadBeanClassException:错误   装载班   [org.springframework.security.provisioning.JdbcUserDetailsManager] for   豆的名字   &#39; org.springframework.security.provisioning.JdbcUserDetailsManager#0&#39;   以null定义:类文件或依赖类的问题;嵌套   异常是java.lang.NoClassDefFoundError:   组织/ springframework的/ JDBC /核心/支持/ JdbcDaoSupport。请参阅   server.log获取更多详细信息。

我将登录bean放在这里,因为我发现它很奇怪。

public LoginBean() {
}

public String doLogin() throws IOException, ServletException {
    ExternalContext context = FacesContext.getCurrentInstance()
            .getExternalContext();

    RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
            .getRequestDispatcher("/j_spring_security_check?j_username="
                    + userName + "&j_password=" + password);

    // Forwards to original destination or to error page
    dispatcher.forward((ServletRequest) context.getRequest(),
            (ServletResponse) context.getResponse());
    FacesContext.getCurrentInstance().responseComplete();

    // It's OK to return null here because Faces is just going to exit.
    return null;
}
//get&sets
}

1 个答案:

答案 0 :(得分:1)

你的推理&#39;原因是错误的。是的,无法重新引用bean的引用,因为无法创建bean,而bean又由以下原因引起:

java.lang.NoClassDefFoundError: org/springframework/jdbc/core/support/JdbcDaoSupport. Please see server.log for more details.

可以在stacktrace的最后一行找到