gpt4 book ai didi

java - 线程 main 中的异常 - maven 依赖

转载 作者:行者123 更新时间:2023-12-01 11:31:20 24 4
gpt4 key购买 nike

public class BatchLauncherSpring {

public static void main(String[] args) {

ApplicationContext context = new ClassPathXmlApplicationContext(
"application-context.xml");

//////
}
}

当我运行 main 方法时,出现 ClassNotFoundException。 Spring 依赖项是通过 Maven 添加的,这些依赖项在编译时解析。有很多类似的问题,但当代码打包为 jar 并在 eclipse 外部执行时,每个人似乎都遇到了问题。当我在 eclipse 本身中运行它时,我实际上遇到了这个问题。

这是pom文件

<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">

<parent>
<groupId>com.mycompany</groupId>
<artifactId>mybatch</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>mybatchCore</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>mybatchCore</name>
<url></url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>3.2.2.RELEASE</spring.version>
<spring.batch.version>2.2.5.RELEASE</spring.batch.version>
</properties>

<dependencies>
<dependency>
<groupId>com.my.repo</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.my.repo</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.my.repo</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.my.repo</groupId>
<artifactId>spring-batch-core</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<dependency>
<groupId>com.my.repo</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>${spring.batch.version}</version>
</dependency>


</dependencies>

</project>

堆栈跟踪

java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) Exception in thread "main"

这里有什么问题吗?谢谢!

最佳答案

你需要 spring-context 依赖快乐编码

关于java - 线程 main 中的异常 - maven 依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30359328/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com