简体   繁体   English

Spring Boot找不到主类

[英]Spring Boot can't find main class

like mentioned in the title I have a Spring Boot project. 就像标题中提到的,我有一个Spring Boot项目。 Trying to start the project out of my IDE it says, that the main class can't be found. 试图从我的IDE中启动项目时,它说找不到主类。

I've found a relative equivalent question here: Spring Boot Program cannot find main class 我在这里找到一个相对等价的问题: Spring Boot程序找不到主类

But the solution doesn't do it for me (I already configured the main class in the pom.xml) like this: 但是该解决方案无法为我做到这一点(我已经在pom.xml中配置了主类),如下所示:

<properties>
    <start-class>de.main.Main</start-class>
    <java.version>1.8</java.version>
</properties>

And this is what my main class looks like: 这就是我的主要班级的样子:

package de.main;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class Main extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Main.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
}

Additional to this an other project, which uses Spring Boot aswell, works totaly fine. 除此之外,另一个使用Spring Boot的项目也可以正常工作。 And the pom.xml is configured the same way in both projects. 在两个项目中,pom.xml的配置方式相同。

I use Spring Boot version 1.5.2 and eclipse oxygen. 我使用的是Spring Boot 1.5.2版,并且会偏食氧气。

The errormessage looks like this: "Fehler: Hauptklasse de.main.Main konnte nicht gefunden oder geladen werden" Roughly translated: "Error: main class de.main.Main can't be found or loaded" 错误消息看起来像这样:“ Fehler:Hauptklasse de.main.Main常见问题解答”粗略翻译:“ Error:无法找到或加载主类de.main.Main”

My Project structure is like this: 我的项目结构是这样的:

Project
|--- Java Resources
|       |--- src
|       |     |----de.main
|       |
|       |--- WebContent
|
|--- pom.xml

Try to execute the current file like Run as -> Java Application . 尝试执行当前文件,例如Run as > Java Application Then confirm it is running or not, then you can run the entire project at a time by Run as -> Spring Boot App . 然后确认它是否正在运行,然后可以通过Run as > Spring Boot App一次运行整个项目。 Try to post the directory structure of the project. 尝试发布项目的目录结构。

请仔细检查您的Main类是否位于src/main/java/de/main/目录下。

Found the reason by running the program via. 通过运行程序找到原因。 cmd - some unnecessary dependencies caused trouble. cmd-一些不必要的依赖项引起了麻烦。 Fixed the problem by deleting them. 通过删除它们来解决问题。

I had the same problem. 我有同样的问题。 It worked for me after I did a maven build with goal set to test. 在我完成了要测试的目标的Maven构建后,它对我有用。 (rightclick on project -> run as -> maven build ... -> when prompted what goal put test) (右键单击项目->运行--maven build ...->提示什么目标进行测试时,单击鼠标右键)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM