java.lang.ClassNotFoundException: org.springframework.core.io.Resource
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24259508/
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
java.lang.ClassNotFoundException: org.springframework.core.io.Resource
提问by Renaud is Not Bill Gates
I'm using spring 4.0.5, Hibernate 4.3.5 and JSF for web developpement in eclipse, and this is the content of my lib
folder :
我在 Eclipse 中使用 spring 4.0.5、Hibernate 4.3.5 和 JSF 进行 web 开发,这是我lib
文件夹的内容:
When I run my project I get this error :
当我运行我的项目时,我收到此错误:
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/EMaEval]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:799)
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.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/EMaEval]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/io/Resource
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:90)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:63)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:403)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:879)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.Resource
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 20 more
these are the configuration files :
这些是配置文件:
web.xml
web.xml
<?xml version="1.0" encoding="ASCII"?>
<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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name></display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/application-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
application-context.xml
application-context.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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/ schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value ="org.postgresql.Driver" />
<property name="user" value="postgres" />
<property name="password" value="toor"/>
<property name="jdbcUrl" value="jdbc:postgresql://172.16.83.128:5432/emaeval" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.models" />
<property name="hibernateProperties">
<props>
<prop key="hiberante.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
</props>
</property>
</bean>
<bean id="tansactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:annotation-config/>
<context:component-scan base-package="com"></context:component-scan>
</beans>
How can I solve this probelm ?
我该如何解决这个问题?
采纳答案by Engineer
Make sure, following jar file included in your class path and lib folder.
确保遵循类路径和 lib 文件夹中包含的 jar 文件。
spring-core-3.0.5.RELEASE.jar
spring-core-3.0.5.RELEASE.jar
if you are using maven, make sure you have included dependency for spring-core-3xxxxx.jar file
如果您使用的是 maven,请确保已包含 spring-core-3xxxxx.jar 文件的依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
Note : Replace ${org.springframework.version} with version number.
注意:将 ${org.springframework.version} 替换为版本号。
回答by Ralph
org.springframework.core.io.Resource
is part of spring-core-<version>.jar
org.springframework.core.io.Resource
是其一部分 spring-core-<version>.jar
But this lib is already in your lib folder. So I guess it is just a Deployment Problem. -- Try to clean your server and redeploy your application.
但是这个 lib 已经在你的 lib 文件夹中了。所以我想这只是一个部署问题。-- 尝试清理您的服务器并重新部署您的应用程序。
回答by Sabyasachi
Right-Click on your project -> Properties -> Deployment Assembly.
右键单击您的项目 -> 属性 -> 部署程序集。
On the Left-hand panel Click 'Add' and add the 'Project and External Dependencies'.
在左侧面板上单击“添加”并添加“项目和外部依赖项”。
'Project and External Dependencies' will have all the spring related jars deployed along with your application
“项目和外部依赖项”将与您的应用程序一起部署所有与 spring 相关的 jar
回答by MangduYogii
There is a version conflict between jar/dependency please check all version of spring is same. if you use maven remove version of dependency and use Spring.io dependency.it handle version conflict. Add this in your pom
jar/依赖项之间存在版本冲突,请检查所有版本的 spring 是否相同。如果您使用 maven 删除依赖版本并使用 Spring.io dependency.it 处理版本冲突。在你的 pom 中添加这个
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>2.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
回答by Sabir Khan
I received same error despite jar being in lib directory & added to deployment assembly in Eclipse.
尽管 jar 在 lib 目录中并添加到 Eclipse 中的部署程序集,但我收到了同样的错误。
So I doubted two things ,
所以我怀疑两件事,
1.Some Weblogic cache issue - as this app was deployed before & I was trying to redeploy after some changes
1. 一些 Weblogic 缓存问题 - 因为这个应用程序是之前部署的,我试图在一些更改后重新部署
2.Jar itself is corrupt due to partial download etc
2.由于部分下载等原因,Jar本身已损坏
So I re downloaded the jar & deleted everything in directory - ..\Oracle_Home\user_projects\domains\base_domain\liband redeployed again & all went well.
所以我重新下载了 jar 并删除了目录中的所有内容 - ..\Oracle_Home\user_projects\domains\base_domain\lib并再次重新部署并且一切顺利。