java - Spring Cloud 任务上的 java.lang.ClassNotFoundException
问题描述
我正在尝试一个简单的 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 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>
多次更改标签的值,但它所做的只是更新错误中提到的包。任何帮助都感激不尽。
解决方案
我认为您需要.java
从 pom.xml 中的这一行中删除:
<start-class>com.example.sampletask.demotask.DemoTaskApplication.java</start-class>
我建议你去start.spring.io使用最新版本的 spring-boot 和 spring-cloud-task 生成一个项目,尽管你在 pom.xml 中的版本现在已经很旧了。
推荐阅读
- r - 如何正确绘制R中给定椭圆的半长(半短)轴?
- r - 如何以自定义格式重组字符?
- laravel - Laravel 授权策略在显示页面上不起作用
- django - Ajax 请求未触发 Django 中 HTTPS 端口 443 上的进度事件
- sql - SQL将列中的日期与系统日期进行比较
- php - 使用 PHP 发送带有 PDF 附件的电子邮件 - 文件已损坏
- android - 在后退按钮上,如何在 XML 布局中定义的片段被另一个片段替换后显示
- node.js - 本地存储节点插件事件以供以后回调
- sql - AWS Timestream / Grafana 查询
- flutter - 如何实现搜索功能?