英文:
java.lang.ClassNotFoundException on a Spring Cloud Task
问题
我正在尝试一个简单的Spring Cloud Task应用程序。我目前正在尝试运行这个应用程序,但不知何故,我遇到了一个 java.lang.ClassNotFoundException: com.example.sampletask.demotask.DemoTaskApplication.java
的错误。我试图调整 pom.xml
文件,但迄今为止没有进展。以下是我现在的情况:
应用程序类:
package com.example.sampletask.demotask;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableTask
public class DemoTaskApplication {
@Bean
public CommandLineRunner commandLineRunner() {
return new HelloWorldCommandLineRunner();
}
public static void main(String[] args) {
SpringApplication.run(DemoTaskApplication.class, args);
}
public static class HelloWorldCommandLineRunner implements CommandLineRunner {
public void run(String... arg0) throws Exception {
System.out.println("Hello, World!");
}
}
}
这是我的 pom.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.sampletask</groupId>
<artifactId>demo-task</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-task</name>
<description>Demo project for Spring Boot</description>
<properties>
<!-- <java.version>11</java.version> -->
<start-class>com.example.sampletask.demotask.DemoTaskApplication.java</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我认为我应该也添加一个 application.properties 文件:
logging.level.org.springframework.cloud.task=DEBUG
spring.application.name=helloWorld
迄今为止,我尝试了多次更改 start-class
标签的值,但它只是更新了错误中提到的包名。非常感谢您的任何帮助。
英文:
I'm trying out a simple Spring Cloud Task application. I'm currently trying to run the said application but somehow I'm ending up with a java.lang.ClassNotFoundException: com.example.sampletask.demotask.DemoTaskApplication.java
. I'm trying to tweak the pom.xml
file but I'm getting no where so far. Here's what I have as of now:
The application class:
package com.example.sampletask.demotask;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableTask
public class DemoTaskApplication {
@Bean
public CommandLineRunner commandLineRunner() {
return new HelloWorldCommandLineRunner();
}
public static void main(String[] args) {
SpringApplication.run(DemoTaskApplication.class, args);
}
public static class HelloWorldCommandLineRunner implements CommandLineRunner {
public void run(String... arg0) throws Exception {
System.out.println("Hello, World!");
}
}
}
Here's my pom:
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.sampletask</groupId>
<artifactId>demo-task</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-task</name>
<description>Demo project for Spring Boot</description>
<properties>
<!-- <java.version>11</java.version> -->
<start-class>com.example.sampletask.demotask.DemoTaskApplication.java</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And I thought I should add the application.properties as well:
logging.level.org.springframework.cloud.task=DEBUG
spring.application.name=helloWorld
What I tried so far is changing the value of the <start-class>
tag couple of times but all it does is update the package mentioned in the error. Any help will be much appreciated.
答案1
得分: 1
我认为你需要在你的 pom.xml 文件中的这一行中去掉 .java
:
<start-class>com.example.sampletask.demotask.DemoTaskApplication.java</start-class>
我建议你访问 start.spring.io,使用最新版本的 spring-boot 和 spring-cloud-task 生成一个项目,因为你在 pom.xml 中使用的版本现在相当旧了。
英文:
I think you need to drop the .java
from this line in your pom.xml:
<start-class>com.example.sampletask.demotask.DemoTaskApplication.java</start-class>
I suggest you go to start.spring.io to generate a project with the latest versions of spring-boot and spring-cloud-task though as the versions you have in your pom.xml are quite old now.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论