我知道问题已经被问到,但没有一个解决方案适合我。 任何人都可以帮我这个。我只是春天的初学者。
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.openid.OpenIDAuthenticationFilter#0': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/openid4java/consumer/ConsumerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:892)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:272)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:196)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
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$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoClassDefFoundError: org/openid4java/consumer/ConsumerException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getDeclaredConstructor(Class.java:1985)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:64)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:939)
... 23 more
Caused by: java.lang.ClassNotFoundException: org.openid4java.consumer.ConsumerException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
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">
<display-name>WeeklySummary</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/rest/*</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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener- class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
调度-servlet.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<context:property-placeholder location="classpath:jdbc.properties" />
<context:component-scan base-package="com.kratin" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="order" value="1" />
<property name="messageConverters">
<list>
<!-- Default converters -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.FormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</list>
</property>
</bean>
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.kratin.domain.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
的applicationContext-security.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.xsd">
<http use-expressions="true">
<intercept-url pattern="/**" access="permitAll" />
<openid-login>
<attribute-exchange>
<openid-attribute name="email" type="http://axschema.org/contact/email" required="true" />
<openid-attribute name="fullname" type="http://axschema.org/namePerson" />
<openid-attribute name="first" type="http://axschema.org/namePerson/first" />
<openid-attribute name="last" type="http://axschema.org/namePerson/last" />
</attribute-exchange>
</openid-login>
<logout />
</http>
<!-- In our example we need to specify own UserService, to keep all logged-in users in the memory storage -->
<beans:bean id="org.springframework.security.authenticationManager" class="org.springframework.security.authentication.ProviderManager">
<beans:property name="providers">
<beans:list>
<beans:ref local="demoAuthenticationProvider"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="demoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<beans:property name="userDetailsService" ref="userDetailsService"/>
<!-- property name="passwordEncoder" ref="passwordEncoder"/ -->
</beans:bean>
<beans:bean id="userDetailsService" class="com.kratin.service.InMemoryUserDetailsService"/>
<!-- Handler to receive success openId response and create new user -->
<beans:bean id="org.springframework.security.openid.ext.OpenIdAuthenticationHandler"
class="com.kratin.controller.DemoAuthenticationSuccessHandler">
<beans:property name="userDetailsService" ref="userDetailsService"/>
</beans:bean>
的login.jsp:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Spring-Security-Step2 Sample Web-Application</title>
</head>
<body>
<sec:authorize access="isAnonymous()">
<h1> Login with OpenID </h1>
<a href="j_spring_openid_security_check?openid_identifier=https://www.google.com /accounts/o8/id">Login via Google</a><br></br>
<a href="j_spring_openid_security_check?openid_identifier=http://www.yahoo.com">Login via Yahoo</a><br></br>
<form name="myOpenIdForm" action="j_spring_openid_security_check" method="post">
<input type="hidden" name="openid_identifier" value=""/>
<input type='text' name='my_open_id' value=''/>.myopenid.com
<input name="submit"
type="submit"
class="rsButton"
value="Login via MyOpenId"
onClick="onMyOpenId();"/>
</form>
<form name="googleAppsForm" action="j_spring_openid_security_check" method="post">
Login into Google Apps Domain
<input type="hidden" name="openid_identifier" value=""/>
Google Apps Domain: <input type='text' name='google_apps_domain' value=''/>
<input name="submit"
type="submit"
class="rsButton"
value="Login into Google Apps"
onClick="onGoogleApps();"/>
</form>
<form name="openIdForm" action="j_spring_openid_security_check" method="post">
Login via any Open ID Provider
<input type='text' name='openid_identifier' value=''/>
<input name="submit" type="submit" class="rsButton" value="Login via OpenID"/>
</form>
<script>
function onMyOpenId() {
var myOpenIdName = document.myOpenIdForm.my_open_id.value;
document.myOpenIdForm.openid_identifier.value='http://' + myOpenIdName + '.myopenid.com';
}
function onGoogleApps() {
var googleAppsDomain = document.googleAppsForm.google_apps_domain.value;
document.googleAppsForm.openid_identifier.value='https://www.google.com/accounts /o8/site-xrds?hd='+googleAppsDomain;
}
</script>
</sec:authorize>
<sec:authorize access="isAuthenticated()">
DemoUserDetails currentUser = (DemoUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
<%-- OpenID: <%=currentUser.getUsername() %><br></br>
Email: <%=currentUser.getEmail() %><br></br>
Full Name: <%=currentUser.getFullName() %><br></br> --%>
<a href="j_spring_security_logout">Logout</a>
</sec:authorize>
</body>
</html>
答案 0 :(得分:1)
查看根本原因:
java.lang.ClassNotFoundException:org.openid4java.consumer.ConsumerException
为此文件添加jar
答案 1 :(得分:0)
您在类路径中找不到类的异常。
Caused by: java.lang.ClassNotFoundException: org.openid4java.consumer.ConsumerException
你必须在你的类路径中放入openid4java jar。 你可以从中得到它 https://code.google.com/p/openid4java/downloads/list