[springboot] spring-boot:run 命令启动报错,Unable to find a suitable main class, please add a 'mainClass'
spring-boot
spring-projects/spring-boot: 是一个用于简化Spring应用开发的框架。适合用于需要快速开发企业级Java应用的项目。特点是可以提供自动配置、独立运行和内置的Tomcat服务器,简化Spring应用的构建和部署。
项目地址:https://gitcode.com/gh_mirrors/sp/spring-boot

·
问题描述:
使用maven命令 spring-boot:run 启动springboot项目报错:
Unable to find a suitable main class, please add a ‘mainClass’ property
问题解决:
首先我是能确定我没有错误,通过java类可以启动项目,但是spring-boot:run命令就是无法启动项目.
1 首先根据网上的建议在pom配置文件插件设置中加:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 加入以下部分-->
<configuration>
<mainClass>class_name</mainClass>
</configuration>
</plugin>
</plugins>
</build>
我试了以后没有作用
2 首先通过java类启动springboot项目
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
可以成功启动,保持启动状态
执行spring-boot:run命令启动,会出现spring的图标但是之后还是会报错
此时再关闭java类启动的线程,再执行spring-boot:run命令启动.
我是这样启动成功了 .




spring-projects/spring-boot: 是一个用于简化Spring应用开发的框架。适合用于需要快速开发企业级Java应用的项目。特点是可以提供自动配置、独立运行和内置的Tomcat服务器,简化Spring应用的构建和部署。
最近提交(Master分支:9 天前 )
fc68b001
Drop `isImmutable` and `getPrefix` from `OriginLookup` since
they're not really Origin concerns. Now that `env` is a
foundational layer we can add a dedicated `PropertySourceInfo`
interface and add that to the `o.s.b.env` package without
creating a package tangle.
Closes gh-45547
7 小时前
24c25aea
Update rules to ensure foundational layers don't depend on the
`org.springframework.boot` package.
Closes gh-47232
7 小时前
更多推荐
所有评论(0)