Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 找不到合适的主类,请添加一个';mainClass';属性,Spring boot_Java_Spring_Maven - Fatal编程技术网

Java 找不到合适的主类,请添加一个';mainClass';属性,Spring boot

Java 找不到合适的主类,请添加一个';mainClass';属性,Spring boot,java,spring,maven,Java,Spring,Maven,嗨,朋友们,我正在开发一个基于SpringBootMaven的项目,并且我已经创建了一个maven子模块,但是当我尝试运行我的项目时,它给出了一个错误 [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project demo-jhipster: Unable to find a suitable main clas

嗨,朋友们,我正在开发一个基于SpringBootMaven的项目,并且我已经创建了一个maven子模块,但是当我尝试运行我的项目时,它给出了一个错误

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project demo-jhipster: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.5.RELEASE:run (default-cli) on project demo-jhipster: Unable to find a suitable main class, please add a 'mainClass' property
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
我的父母波姆和孩子波姆是

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>1.2.5.RELEASE</version>
        <relativePath />
    </parent>

    <groupId>com.aquevix.demo</groupId>
    <artifactId>demo-jhipster</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>demo_jhipster</name>

    <prerequisites>
        <maven>3.0.0</maven>
    </prerequisites>
    <modules>
        <module>JhipsterSubmodule</module>
    </modules>

    <properties>
        <assertj-core.version>3.1.0</assertj-core.version>
        <awaitility.version>1.4.0</awaitility.version>
        <commons-io.version>2.4</commons-io.version>
        <commons-lang.version>2.6</commons-lang.version>
        <gatling-maven-plugin.version>2.1.6</gatling-maven-plugin.version>
        <gatling.version>2.1.6</gatling.version>
        <hibernate.version>4.3.10.Final</hibernate.version>
        <hikaricp.version>2.4.0</hikaricp.version>
        <jacoco-maven-plugin.version>0.7.4.201502262128</jacoco-maven-plugin.version>
        <java.version>1.8</java.version>
        <javax.inject.version>1</javax.inject.version>
        <joda-time-hibernate.version>1.4</joda-time-hibernate.version>
        <liquibase-hibernate4.version>3.5</liquibase-hibernate4.version>
        <liquibase-slf4j.version>1.2.1</liquibase-slf4j.version>
        <liquibase.version>3.4.1</liquibase.version>
        <mapstruct.version>1.0.0.CR1</mapstruct.version>
        <maven-enforcer-plugin.version>1.3.1</maven-enforcer-plugin.version>
        <maven-sortpom-plugin.version>2.3.0</maven-sortpom-plugin.version>
        <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <metrics-spark-reporter.version>1.2</metrics-spark-reporter.version>
        <metrics-spring.version>3.1.2</metrics-spring.version>
        <!-- Sonar properties -->
        <project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
        <run.addResources>false</run.addResources>
        <sonar-maven-plugin.version>2.6</sonar-maven-plugin.version>
        <sonar.exclusions>src/main/webapp/assets/**/*.*, src/main/webapp/bower_components/**/*.*, src/main/webapp/dist/**/*.*</sonar.exclusions>
        <sonar.jacoco.itReportPath>${project.testresult.directory}/coverage/jacoco/jacoco-it.exec</sonar.jacoco.itReportPath>
        <sonar.jacoco.reportPath>${project.testresult.directory}/coverage/jacoco/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>

        <sonar.javascript.jstestdriver.reportsPath>${project.testresult.directory}/karma</sonar.javascript.jstestdriver.reportsPath>
        <sonar.javascript.lcov.reportPath>${project.testresult.directory}/coverage/report-lcov/lcov.info</sonar.javascript.lcov.reportPath>

        <sonar.sources>${project.basedir}/src/main/</sonar.sources>
        <sonar.surefire.reportsPath>${project.testresult.directory}/surefire-reports</sonar.surefire.reportsPath>
        <sonar.tests>${project.basedir}/src/test/</sonar.tests>
        <spring-security.version>4.0.2.RELEASE</spring-security.version>
        <springfox.version>2.0.3</springfox.version>
        <usertype-core.version>4.0.0.GA</usertype-core.version>

    </properties>

    <dependencies>
        // dependencies..
    </dependencies>
    <build>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <filtering>false</filtering>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>**/*.xml</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>com.google.code.sortpom</groupId>
                <artifactId>maven-sortpom-plugin</artifactId>
                <version>${maven-sortpom-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>sort</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sortProperties>true</sortProperties>
                    <nrOfIndentSpace>4</nrOfIndentSpace>
                    <sortDependencies>groupId,artifactId</sortDependencies>
                    <sortPlugins>groupId,artifactId</sortPlugins>
                    <keepBlankLines>true</keepBlankLines>
                    <expandEmptyElements>false</expandEmptyElements>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>${gatling-maven-plugin.version}</version>
                <configuration>
                    <configFolder>src/test/gatling/conf</configFolder>
                    <dataFolder>src/test/gatling/data</dataFolder>
                    <resultsFolder>target/gatling/results</resultsFolder>
                    <bodiesFolder>src/test/gatling/bodies</bodiesFolder>
                    <simulationsFolder>src/test/gatling/simulations</simulationsFolder>
                    <!-- This will force Gatling to ask which simulation to run
                      This is useful when you have multiple simulations -->
                    <simulationClass>*</simulationClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>${maven-enforcer-plugin.version}</version>
                <executions>
                    <execution>
                        <id>enforce-versions</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <rules>
                        <requireMavenVersion>
                            <message>You are running an older version of Maven. JHipster requires at least Maven 3.0</message>
                            <version>[3.0.0,)</version>
                        </requireMavenVersion>
                        <requireJavaVersion>
                            <message>You are running an older version of Java. JHipster requires at least JDK ${java.version}</message>
                            <version>[${java.version}.0,)</version>
                        </requireJavaVersion>
                    </rules>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Xmx256m ${surefireArgLine}</argLine>
                    <!-- Force alphabetical order to have a reproducible build -->
                    <runOrder>alphabetical</runOrder>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.2.4</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <defaultOutputDirectory>${project.build.directory}/generated-sources</defaultOutputDirectory>
                    <processors>
                        <processor>org.mapstruct.ap.MappingProcessor</processor>
                    </processors>
                    <options>
                        <mapstruct.suppressGeneratorTimestamp>true</mapstruct.suppressGeneratorTimestamp>
                        <mapstruct.defaultComponentModel>spring</mapstruct.defaultComponentModel>
                    </options>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${sonar-maven-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>pre-unit-tests</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <!-- Sets the path to the file which contains the execution data. -->
                            <destFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</destFile>
                            <!-- Sets the name of the property containing the settings for JaCoCo runtime agent. -->
                            <propertyName>surefireArgLine</propertyName>
                        </configuration>
                    </execution>
                    <!-- Ensures that the code coverage report for unit tests is created after unit tests have been run -->
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</dataFile>
                            <outputDirectory>${project.testresult.directory}/coverage/jacoco</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>${liquibase.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.javassist</groupId>
                        <artifactId>javassist</artifactId>
                        <version>3.18.2-GA</version>
                    </dependency>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate4</artifactId>
                        <version>${liquibase-hibernate4.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-jpa</artifactId>
                        <version>${project.parent.version}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                    <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
                    <driver />
                    <url />
                    <defaultSchemaName />
                    <username />
                    <password />
                    <referenceUrl>hibernate:spring:com.aquevix.demo.domain?dialect=</referenceUrl>
                    <verbose>true</verbose>
                    <logging>debug</logging>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
                    <arguments>
                        <argument>--spring.profiles.active=dev</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>fast</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <arguments>
                                <argument>--spring.profiles.active=dev,fast</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>DEBUG</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-undertow</artifactId>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.trecloux</groupId>
                        <artifactId>yeoman-maven-plugin</artifactId>
                        <version>0.4</version>
                        <executions>
                            <execution>
                                <id>run-frontend-build</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <configuration>
                                    <buildTool>grunt</buildTool>
                                    <buildArgs>build --force --no-color</buildArgs>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <yeomanProjectDirectory>${project.basedir}</yeomanProjectDirectory>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>2.5</version>
                        <configuration>
                            <filesets>
                                <fileset>                                       <directory>src/main/webapp/dist</directory>
                                </fileset>
                                <fileset>
                                    <directory>.tmp</directory>
                                </fileset>
                                <fileset>
                                    <directory>node_modules</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <arguments>
                                <argument>--spring.profiles.active=prod</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- log configuration -->
                <logback.loglevel>INFO</logback.loglevel>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

4.0.0

您的应用程序中是否有一个类具有以下主要方法:

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

或者您是否有多个带有主方法的类,在这种情况下Spring无法确定使用哪一个?

我相信我遇到的问题与您的类似。我有一个使用Spring Boot的多模块应用程序,只有一个Application.java(使用main方法)

我正在努力用Maven启动它,结果和你的一样(找不到合适的主类)

我花了几个小时尝试和更改内容,在将属性mainClass添加到pom后,它找不到它

然后我决定不从根项目而是从应用程序类所在的项目运行该项目

通过这样做,我能够启动Spring Boot,一切都像一个魔咒一样工作

更新 如果您想用
java-jar文件
打包要执行的全部内容,您可以从根项目运行以下命令:

mvn clean package spring-boot:repackage 

不要忘记将
spring boot maven插件添加到pom中。

您可以通过指定main的位置来解决此问题,如下所示:

   mvn spring-boot {com.ishanitech.controller.Application}:run

解决方案是更改pom.xml文件

由此

<packaging>pom</packaging>
pom
对此

<packaging>war</packaging>
战争
或根据部署方法需要的其他值

mvn clean spring-boot:start
…会给你同样的错误

mvn clean package spring-boot:start

如果您试图在项目根目录中运行
mvn spring boot:run
或仅运行
mvn
(您似乎使用JHipster,这是他们将其连接为默认目标的方式),那么…将通过在运行
sprint boot:start

之前构建工件来修复此问题,这是正常的,如果失败,根据我认为它只能用于一个普通的春季启动项目

由于您的父项目似乎有几个Spring Boot Web应用程序,我猜每个应用程序都有自己的main()启动类,您只是使用父pom分解pom,并能够通过单个命令单独打包所有应用程序


因此,在这种情况下,只需运行一个
mvn包,而不是
mvn
mvn spring boot:run

也许您忘记了指定要启动的主类

在pom.xml中:

<properties>
    <start-class>com.ishanitech.controller.Application</start-class>
</properties>

com.ishanitech.controller.Application

从父pom中删除maven build插件代码,如下所示,下面的代码片段应仅位于子模块pom中,其中您有spring boot应用程序的主类:

  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

org.springframework.boot
springbootmaven插件

我也遇到了同样的问题,但通过在pom.xml中添加以下行,我解决了我的项目的问题:

<properties>
      <start-class>com.hls.om.wp.AgencySearch</start-class>
</properties>

com.hls.om.wp.AgencySearch

其中,
AgencySearch
类具有运行spring boot应用程序的主要方法。

如果您使用的是
IntellJ IDEA
,也许您可以这样做:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>add.your.main.class.application.reference.here</mainClass>
    </configuration>
</plugin>
+- com.domain.myapp.app
|  \- Application.java
+- com.domain.myapp.controllers
|  \- AppController.java
+- com.domain.myapp.entities
|  \- AppEntity.java
+- com.domain.myapp.services
|  \- AppService.java
+- com.domain.myapp.repository
|  \- AppRepo.java
+- com.domain.myapp
 |  \- Application.java
 |  +- com.domain.myapp.controllers
 |  |  \- AppController.java
 |  +- com.domain.myapp.entities
 |  |  \- AppEntity.java
 |  +- com.domain.myapp.services
 |  |  \- AppService.java
 |  +- com.domain.myapp.repository
 |  |  \- AppRepo.java

org.springframework.boot
springbootmaven插件
在此处添加.your.main.class.application.reference

这就解决了我的错误。

如果你按照官方指南并将存储库克隆到本地,那么你就进入文件夹,指南让你
cd initial
,不要这样做,
cd complete
,就不会有问题。

在我的情况下,我在主pom中有:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
</parent>

org.springframework.boot
spring启动程序父级
2.0.3.1发布
whitch包括插件spring boot maven插件

我不得不添加到主pom以跳过它:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <skip>true</skip>
        </configuration>
    </plugin>

org.springframework.boot
springbootmaven插件
真的
然后在具有ma应用程序类的模块中:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <skip>false</skip>
        </configuration>
    </plugin>

org.springframework.boot
springbootmaven插件
假的

我也有同样的问题。在我的例子中,这是因为我的主类位于一个包中,而该包不是包含控制器、实体等的其他包的“父”包。类似于这样:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>add.your.main.class.application.reference.here</mainClass>
    </configuration>
</plugin>
+- com.domain.myapp.app
|  \- Application.java
+- com.domain.myapp.controllers
|  \- AppController.java
+- com.domain.myapp.entities
|  \- AppEntity.java
+- com.domain.myapp.services
|  \- AppService.java
+- com.domain.myapp.repository
|  \- AppRepo.java
+- com.domain.myapp
 |  \- Application.java
 |  +- com.domain.myapp.controllers
 |  |  \- AppController.java
 |  +- com.domain.myapp.entities
 |  |  \- AppEntity.java
 |  +- com.domain.myapp.services
 |  |  \- AppService.java
 |  +- com.domain.myapp.repository
 |  |  \- AppRepo.java
解决方案是将我的主类移动到一个包中,该包在层次结构上位于其他包的顶部,因为Spring Boot会自动搜索该包和所有子包中带有@Entity、@Component、@Service、@Repository注释的类。结果是这样的:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>add.your.main.class.application.reference.here</mainClass>
    </configuration>
</plugin>
+- com.domain.myapp.app
|  \- Application.java
+- com.domain.myapp.controllers
|  \- AppController.java
+- com.domain.myapp.entities
|  \- AppEntity.java
+- com.domain.myapp.services
|  \- AppService.java
+- com.domain.myapp.repository
|  \- AppRepo.java
+- com.domain.myapp
 |  \- Application.java
 |  +- com.domain.myapp.controllers
 |  |  \- AppController.java
 |  +- com.domain.myapp.entities
 |  |  \- AppEntity.java
 |  +- com.domain.myapp.services
 |  |  \- AppService.java
 |  +- com.domain.myapp.repository
 |  |  \- AppRepo.java
希望有帮助


关于

我通过两个步骤解决了这个问题:

  • 在父模块文件夹中,运行
    mvn安装
  • 转到包含所需mainClass的子模块文件夹,运行
    mvn clean spring boot:start

  • 如果不想创建胖罐子,可以在pom.xml中添加以下行:

    <properties>
        <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
    </properties>
    
    
    真的
    
    唯一有效的方法是在父级和模块pom.xml中分别精确地包含这些内容:

    家长:

    <build>
            <pluginManagement><!-- lock down plugins versions to avoid using Maven 
                    defaults (may be moved to parent pom) -->
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </plugin>
                    <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>3.1.0</version>
                    </plugin>
                    <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>3.0.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.8.0</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.22.1</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>3.0.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-install-plugin</artifactId>
                        <version>2.5.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>2.8.2</version>
                    </plugin>
                    <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
                    <plugin>
                        <artifactId>maven-site-plugin</artifactId>
                        <version>3.7.1</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                        <version>3.0.0</version>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    
    
    org.springframework.boot
    springbootmaven插件
    真的
    maven清洁插件
    3.1.0
    maven资源插件
    3.0.2
    maven编译器插件
    3.8.0
    maven surefire插件
    2.22.1
    maven jar插件