【发布时间】:2021-07-04 05:41:25
【问题描述】:
我用 spring initializr 创建了一个 spring maven 项目,它生成了以下 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>2.4.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.spring-docker-test</groupId>
<artifactId>spring-boot-docker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-docker</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
然后我将生成的zip文件解压,导入到Eclipse中,并将项目的目标设置为spring-boot:run
我还添加了一个项目,如here所述
在src/main/java/hello/Application.java
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class Application {
@RequestMapping("/")
public String home() {
return "Hello Docker World";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
现在,当我尝试“运行方式 > Maven 构建”时,我收到以下错误消息
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.8:run (default-cli) on project spring-boot-docker: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.8:run failed: Unable to find a single main class from the following candidates [hello.Application, com.springdockertest.springbootdocker.SpringBootDockerApplication] -> [Help 1]
如何设置单个主类(在pom.xml 文件中?)
【问题讨论】:
标签: java spring eclipse spring-boot maven