当前位置: 首页 > 知识库问答 >
问题:

Spring security无法解析对bean的引用

冯宪
2023-03-14

在尝试部署集成了Spring Security性的jsf项目时,我遇到了以下错误。我今天才开始使用Spring Security性,因为安全领域的javaee安全性太麻烦了。我看了这个教程。所以我不确定这个错误到底意味着什么。我今天也开始了分级,所以我把依赖项包括在内,以防万一。

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

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.

应用程序上下文.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>

我的渐变依赖项:

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 -->

并promise为您提供最大的乐趣,错误作为引用:

无法部署铭文Temp2 部署失败=部署期间发生错误:加载应用程序时出现异常:java.lang.非法状态异常:容器库.addChild:启动:组织.apache.catalina.生命周期异常: 组织.springframework.bean.工厂.Bean创建异常: 创建名称为“组织.springframework.security.filter链”的 Bean 时出错: 无法解析对 Bean 'org.springframework.security.web.默认安全过滤器链 #1' 的引用源列表'与键1;嵌套的异常是组织.springframework.beans.factory.Bean创建异常:使用关键字“组织.springframework.security.web.默认安全过滤器#1”创建Bean时出错:无法解析对bean的引用“组织.springframework.security.web.authentication.用户名密码身份验证过滤器#0”,同时使用键[6]设置构造函数参数;嵌套的异常是组织.springframework.beans.factory.Bean创建异常:创建名称为“org.springframework.security.web.authentication.用户名密码身份验证过滤器#0”的Bean时出错:在设置 bean 属性“身份验证管理器”时,无法解析对 Bean 的引用。嵌套的异常是组织.springframework.bean.factory.Bean创建异常: 创建名称为“org.springframework.security.authentication.提供程序管理器#0”的 Bean 时出错:在设置构造函数参数时无法解析对 Bean 'org.springframework.security.config.authentication.身份验证管理器工厂Bean#0'的引用;嵌套的异常是组织.Spring框架.豆.工厂.豆创建异常: 创建名称为 “组织.Spring框架.安全.config.authentication.身份验证的 Bean 错误:工厂豆在对象创建时引发异常;嵌套的异常是组织.springframework.bean.factory.Bean创建异常:使用键 [0] 设置构造函数参数时,无法解析对 bean “组织.springframework.security.authentication.dao.Dao 身份验证提供程序 #0”的引用;嵌套的异常是组织.springframework.bean.factory.Bean创建异常:创建名称为“org.springframework.security.authentication.dao.Dao 身份验证提供程序#0”的 Bean 时出错:在设置 Bean 属性“用户详细信息服务”时,无法解析对 Bean 的引用”嵌套的异常是组织.Spring框架.豆.工厂.无法加载豆类异常: 错误加载类 [组织.Spring框架.安全.配置.Jdbc用户详细信息管理器] 为 bean 的名称为 'org.springframework.security.provisioning.JdbcUser详细信息管理器 #0' 定义在 空:类文件或依赖类的问题;嵌套的异常是 java.lang.NoClassDefFoundError: org/springframework/jdbc/core/support/JdbcDaoSupport.有关详细信息,请参阅服务器.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个答案

骆文华
2023-03-14

你对原因的“推理”是错误的。是的,对 bean 的引用无法重新打磨,因为无法创建 Bean,而这又是由以下原因引起的:

java.lang.NoClassDefFoundError:org/springframework/jdbc/core/support/JdbcDaoSupport。请参阅服务器。日志了解更多详细信息。

这可以在你的堆栈跟踪的最后一行找到

 类似资料:
  • 我尝试将我的应用程序配置为使用Spring数据 neo4j 。 但是当我提交我的应用程序时,我得到了这个堆栈跟踪跟踪: 这是我的UserRepository: 这是我的porm.xml http://maven.apache.org/maven-v4_0_0.xsd"

  • 我是Spring的新手,在尝试将项目从Java6升级到Java8时遇到了此错误。 我在这里读到,要解决这个问题,要么使用Java 7,要么升级Spring版本。Java 7不行,因为我的目标是升级到Java 8,所以我尝试将Spring版本从2.1.9升级到4.0.0,结果出现以下错误: 以下是相关文件: pom.xml bprpp-memory-context.xml

  • 我的代码中出现了这个错误。 org.springframework.beans.factory.BeanCreationException:创建名为“roleRepository”的bean时出错:设置bean属性“entityManager”时,无法创建[org.springframework.orm.jpa.SharedEntityManagerCreator]类型的内部bean(内部bean

  • 我正在学习OpenApi。我从Swagger那里得到了这个错误: TypeError: O是未定义的值parameter-row.jsx:149渲染root-injects.jsx:93React 8_renderValidatedComponentWithoutOwnerOrContext_renderValidatedComponent性能初始安装安装组件安装组件安装儿童_createInit

  • 我有一个 springboot 应用程序,我在其中连接到 cassandra DB。 我的pom.xml: cassandraConfig 定义: 仓库类: 实体类: 现在,当我启动应用程序时,我遇到了以下错误: 它说cassandraTemplate和sessionFactory的依赖和bean创建问题。我是使用spring-data的新手,所以不确定我错过了什么。 从启动日志,我可以看到它正在

  • Iam使用spring、hibernate maven项目时出现异常,无法在dispatcher servlet上解析对bean“sessionFactory”的引用。xml文件。下面是iam添加的三个文件内容。dispatcherservlet和应用程序上下文都位于resources文件夹中。问题是什么?请帮忙 我的错误:org。springframework。网状物util。NestedSer