运行spring boot Application时无法找到或加载主类

时间:2018-05-03 16:14:21

标签: java spring maven spring-boot

当我将应用程序作为Java应用程序运行时,我遇到了问题。 我尝试了各种解决方案但没有成功。 我仍然收到以下消息:

  

无法找到或加载主类com.alliacom.audit.AuditApplication

这是pom.xml文件

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.alliacom</groupId>
    <artifactId>audit</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>audit</name>
    <description>Alliacom auditing tool</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <repositories>
        <repository>
            <id>lightadmin-nexus-releases</id>
            <url>http://lightadmin.org/nexus/content/repositories/releases</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.15</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
    <mainClass>com.alliacom.audit.AuditApplication</mainClass>
  </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是我的主要应用, AuditApplication.java

package com.alliacom.audit;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class AuditApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {

        SpringApplication.run(AuditApplication.class, args);
    }
}

项目似乎很好, 构建期间没有错误, 但我没有看到问题的原因。

3 个答案:

答案 0 :(得分:0)

尝试从您的pom文件中删除以下内容(不需要):

<configuration>
    <mainClass>com.alliacom.audit.AuditApplication</mainClass>
</configuration>

答案 1 :(得分:0)

最快的解决方案,因为你的pom非常小:

  • Spring Initializer https://start.spring.io/

  • 生成新的 Maven / Java / SpringBoot 2.0 项目。

  • 运行它并检查您的系统是否正常

  • 开始一次添加一个自定义项,并在每次修改后尝试。

几分钟后你就会找到罪魁祸首。

答案 2 :(得分:0)

你需要像这样使用插件

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.0.1.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>