Spring Boot:重命名Main類

[英]Spring Boot: Renaming the Main class

I'm new to Spring and Spring Boot, but I'm using it as a template.

我是Spring和Spring Boot的新手,但我正在使用它作為模板。

The Main.java file contains in part the following:


package com.example;

public class Main {


Unfortunately I need to import another class that is called Main, and use it in this class. The other class is in a Jar and I don't really want to recompile it, so I was thinking the best way would be to rename this Main.


However when I do that (renaming it to JavaGettingStarted), the Maven plugin for Spring Boot will fail:

但是,當我這樣做(將其重命名為JavaGettingStarted)時,Spring Boot的Maven插件將失敗:

[ERROR] Failed to execute goal
(default) on project java-getting-started: Execution default of goal
failed: Unable to find a single main class from the following
candidates [com.example.JavaGettingStarted, com.example.Main] -> [Help

Is Main some sort of default? Can I change it?


1 个解决方案



The problem is not the name of the class, but rather that the Spring Boot Maven plugin detected two classes with a main method. Either delete one of those main methods, or explicitly configure the maven plugin:

問題不是類的名稱,而是Spring Boot Maven插件使用main方法檢測到兩個類。要么刪除其中一個主要方法,要么顯式配置maven插件:

    <mainClass>Your class name here</mainClass>



粤ICP备14056181号  © 2014-2021 ITdaan.com