Java 从 ServletContext 资源解析 XML 文档时出现意外异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19352803/
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
Unexpected exception parsing XML document from ServletContext resource
提问by LoveTW
I find a basic spring security example, but I can't run it usually on tomcat. I know this error message might be caused by the configuration xml file, but I can't find it. Thanks for the help:)
我找到了一个基本的 spring 安全示例,但我通常无法在 tomcat 上运行它。我知道此错误消息可能是由配置 xml 文件引起的,但我找不到它。谢谢您的帮助:)
1. Error Message
1. Error Message
java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2521)
at java.lang.Class.getDeclaredMethods(Class.java:1845)
at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotated
Methods(StandardAnnotationMetadata.java:136)
at org.springframework.context.annotation.ConfigurationClassBeanDefiniti
onReader.checkConfigurationClassCandidate(ConfigurationClassBeanDefinitionReader
.java:318)
2. File Structure
2. File Structure
3. web.xml
3. web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Spring MVC Application</display-name>
<!-- Spring MVC -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<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>
</web-app>
4. mvc-dispatcher-servlet.xml
4. mvc-dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.mkyong.common.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>mymessages</value>
</list>
</property>
</bean>
</beans>
5.spring-security.xml
5.spring-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.3.xsd">
<http auto-config="true">
<intercept-url pattern="/welcome*" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed"
/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="mkyong" password="123456" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
采纳答案by Debojit Saikia
This is a part of your stacktrace
:
这是您的一部分stacktrace
:
Constructor threw exception; nested exception is java.lang.NoC
lassDefFoundError: org/springframework/aop/config/AbstractInterceptorDrivenBeanD
efinitionDecorator
which says that Aspect Oriented Programming (AOP) Framework
jars are not present in the classpath
. So you need to add spring-aop
(spring-aop-3.0.5.RELEASE.jar) jars to your classpath
.
这表示Aspect Oriented Programming (AOP) Framework
.jar 文件中不存在 jars classpath
。所以你需要将spring-aop
(spring-aop-3.0.5.RELEASE.jar) jars 添加到你的classpath
.
回答by Gaurav Varma
You need to add spring.jar to your library. spring-security jars would be referencing it. Hence failing initialization.
您需要将 spring.jar 添加到您的库中。spring-security jars 将引用它。因此初始化失败。
回答by Saurabh
I found same exception in my project but after adding spring-aop-4.1.6.RELEASE.jar i resolved the problem. please be careful about the version of jar which you are going to add in your project... :)
我在我的项目中发现了同样的异常,但是在添加 spring-aop-4.1.6.RELEASE.jar 之后我解决了这个问题。请注意您要添加到项目中的 jar 版本... :)