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>



重命名类会导致IBOutlet连接失败 - Renaming class causes IBOutlet connection to fail 除了重构和重命名类或属性名之外,swift还有什么选项? - What is other option available in swift instead of refactoring and renaming class or attribute name? Spring Boot Program无法找到主类 - Spring Boot Program cannot find main class 暴露给Objective-C代码时Swift类的名称不尊重@objc重命名 - Name of Swift class when exposed to Objective-C code does not respect the @objc renaming 使用south重命名django模型类名和相应的外键,而不会丢失数据 - Renaming a django model class-name and corresponding foreign keys with south, without loosing the data
© 2014-2019 ITdaan.com 粤ICP备14056181号