当我在的时候。尝试使用 ./mvnw spring-boot:run 运行 spring intializr。它显示错误

问题描述 投票:0回答:1
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.3.2:run (default-cli) on project initializr: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

请帮我解决这个问题。

java spring spring-boot maven spring-mvc
1个回答
0
投票

在 pom 的构建部分中,您需要包含 spring-boot-plugin 并定义主类。

<build>
  <plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>             
        <configuration>    
            <mainClass>com.yourpackage.YourMainApplicationClassName</mainClass>
        </configuration>
    </plugin>
  </plugins>
</build>

所以,如果我的主应用程序类是

MainClass
包中的
com.acme
,我会将 mainClass 属性设置为
com.acme.MainClass

© www.soinside.com 2019 - 2024. All rights reserved.