【发布时间】:2022-01-22 19:41:41
【问题描述】:
我最近将我的库从 gradle 5.X 升级到 7.3.1,并将 Spring-Boot 从 2.4.X 升级到 2.6.X,但我遇到了问题。我正在使用 gradle build 创建一个 jar 并在我的服务器上执行这个 jar,它在 Spring-Boot 2.4.X 上运行良好,但现在在 2.6.X 上我遇到了一些问题:
没有主要的清单属性
所以我添加到了我的 build.gradle
jar {
manifest {
attributes "Main-Class": "my.package.MainClass"
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
现在我得到了错误
无法找到或加载主类 my.package.MainClass
如果我切换回 2.4.X,它工作正常。 我的罐子来自:
- spring-boot 2.4.X -> 90Mo
- spring-boot 2.6.X -> 500 Ko
所以我尝试用 shadowJar 创建一个胖 jar 并得到这个错误
错误 org.springframework.boot.SpringApplication - 应用程序运行失败 12 月 21 日 10:04:09 vps-11602ed1 项目 [12706]:org.springframework.context.ApplicationContextException:无法启动 Web 服务器;嵌套异常是 org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean。
如果有人得到有关如何使其与 Spring-boot 2.6.X 一起使用的答案。
提前致谢
【问题讨论】:
-
我试过了: - 我的主类得到了@SpringBootApplication 并且已经从 SpringBootServletInitializer 扩展 - 添加到每个配置文件 spring.main.web-application-type=none - 案例 3 也已经完成 - 我没有使用 tomcat - 我是从 gitlab VM 构建的,所以不需要重新打包或清理 - 尝试添加 spring-boot-starter-parent - spring.profiles.active=default 没有任何效果
标签: java spring-boot gradle jar executable-jar