Spring 安全性无法解析对 bean 的引用
Spring security cannot resolve reference to bean
我在尝试部署集成了 spring 安全性的 jsf 项目时遇到以下错误。我今天刚开始使用 Spring 安全性,因为安全领域的 java ee 安全性太麻烦了。我看了this tutorial。所以我不确定这个错误到底意味着什么。我今天也开始 gradle,所以我包含了我放在那里的依赖项以防万一。
(我会将错误作为引用放在页面底部)。
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 -->
如您所愿,错误如引用:
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.
我会把我的登录 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
}
你的'reasoning'的原因是错误的。是的,无法解析对 bean 的引用,因为无法创建 bean,而这又是由以下原因引起的:
java.lang.NoClassDefFoundError: org/springframework/jdbc/core/support/JdbcDaoSupport. Please see server.log for more details.
可以在堆栈跟踪的最后一行找到
我在尝试部署集成了 spring 安全性的 jsf 项目时遇到以下错误。我今天刚开始使用 Spring 安全性,因为安全领域的 java ee 安全性太麻烦了。我看了this tutorial。所以我不确定这个错误到底意味着什么。我今天也开始 gradle,所以我包含了我放在那里的依赖项以防万一。
(我会将错误作为引用放在页面底部)。
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 -->
如您所愿,错误如引用:
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.
我会把我的登录 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
}
你的'reasoning'的原因是错误的。是的,无法解析对 bean 的引用,因为无法创建 bean,而这又是由以下原因引起的:
java.lang.NoClassDefFoundError: org/springframework/jdbc/core/support/JdbcDaoSupport. Please see server.log for more details.
可以在堆栈跟踪的最后一行找到