我是按照Spring的教程,一切都工作正常,直到我克隆我的项目,现在克隆的项目和原来的项目不想工作,我已经搜索槽整个堆栈溢出类似的问题,我无法解决这个问题,我已经清理了项目,重新启动eclipse,更新,添加和删除依赖项从pom.xml似乎没有什么工作。
这是我的主要课程:
package com.caveofprogramming.spring.test;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.caveofprogramming.spring.test.Offer;
import com.caveofprogramming.spring.test.OfferDAO;
public class Tester {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"com/caveofprogramming/spring/test/beans/beans.xml");
OfferDAO offersDao = (OfferDAO) context.getBean("offerDao");
try {
List<Offer> offers= new ArrayList<Offer>();
offers.add(new Offer(1,"Pepito", "pepito@tcs.com", "i know css and html5"));
offers.add(new Offer(2, "Juancito", "juancito@tcs.com", "i know about rest and play"));
offers.add(new Offer(3, "Juancho Tazo", "jtazo@tcs.com", "im an expert on SPEL and SQL!"));
if(offersDao.Create(offers).length==offers.size()){
for (int i = 0; i < offers.size(); i++) {
System.out.println(offers.get(i).getName()+" record was created succesfully");
}
System.out.println("All the new records were created succesfully");
}
else{
System.out.println("One or more of the records were not createdS");
}
} catch (Exception e) {
e.getMessage();
}
((ClassPathXmlApplicationContext) context).close();
}
}
Beans.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="com.caveofprogramming.spring.test" />
<context:property-placeholder
location="com/caveofprogramming/spring/props/jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven />
</beans>
波姆。xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.caveofprogramming.spring.test</groupId>
<artifactId>spring-tutorial-5</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
</dependencies>
</project>
正如我所说,当我在同一个工作区复制粘贴项目时,一切都开始失败,当然我更改了名称。
这个错误我得到它后做一个maven清洁。
如果我不这么做,我会出错:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [com/caveofprogramming/spring/test/beans/beans.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/context/event/EventListenerFactory
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.caveofprogramming.spring.test.App.main(App.java:13)
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/EventListenerFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.registerTransactionalEventListenerFactory(AnnotationDrivenBeanDefinitionParser.java:92)
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:60)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
... 14 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.event.EventListenerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 36 more
enter code here
看起来你错过了EventListenerFactory类。它在maven artefact组织中定义。springframework spring上下文
在您的pom.xml中添加此工件的依赖项使用相同的版本,就像您的其他Spring工件一样。
正如您在这里看到的它是从4.2开始添加的,请尝试将pom.xml中的所有Spring依赖项更新为4.2.5。RELEASE
。
几天来,我一直在尝试为我的多模块maven项目创建一个可执行的jar文件。但是,当我尝试运行这个jar文件时,我得到“无法找到或加载主类src.main.java.com.domain.MainClass”(为了公司的隐私,我已经更改了名称domain和MainClass) 我已经找了几天了,没有一个明显的提示似乎有效。 我使用的命令:mvn clean package,然后我cd到目标文件夹中,
我使用的是Java Maven程序,我不知道输入什么作为
在Eclipse中,我使用JavaFX、Maven和jre 1.8。0_45。 通常,当我尝试以这种方式使用Maven编译时(运行方式- 当我将其更改为jdk(在配置、窗口属性、maven配置中随处可见)并尝试运行/构建/编译/无论遇到什么错误 没有给我上课。就这个。 我通过在我的pom中添加到javac的路径并保留jre包来解决这个问题 这是可行的。 但我还是想知道——为什么会发生这种错误?我做
问题内容: 我正在尝试使用Gradle运行一个非常简单的项目,并在使用时遇到以下错误: 这是我的文件结构: 我排除了libs和tmp文件夹的内容,因为我认为这与该问题无关,但是我可以在需要时添加它。 这是我的build.gradle文件: 关于如何解决此问题的任何想法?我已经为mainClassName属性尝试了各种方法,但似乎没有任何效果。 问题答案: 我在这里看到两个问题,一个与另一个有关。
我的java应用程序编译有问题。 编译器说:
我用的是软呢帽19。HelloWorld的内容。爪哇: 我可以使用 javac HelloWorld。JAVA 但我无法使用 java HelloWorld 它给出了以下错误 错误:无法找到或加载主类HelloWorld 但我可以用 sudo java HelloWorld 我错过了什么???