gpt4 book ai didi

spring-boot - Spring Boot 1和Gradle:ClassNotFoundException SpringApplicationBuilder

转载 作者:行者123 更新时间:2023-12-03 05:19:54 26 4
gpt4 key购买 nike

我已经为Spring Boot 1.5应用程序配置了Gradle。它可以在Spring Tool Suite中正常运行,但是gradlew build创建的jar文件在BOOT-INF文件夹中没有jar文件。这当然会阻止jar文件的成功执行:

java -jar build\libs\myapp-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/builder/SpringApplicationBuilder
at myapp.boot.Application.runWithContextHierarchy(Application.java:50)
at myapp.boot.Application.main(Application.java:33)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.builder.SpringApplicationBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 10 more
build.gradle摘录:
plugins {
id 'org.springframework.boot' version '1.5.22.RELEASE'
id 'java'
}

dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
...
}

最佳答案

事实证明,Spring Boot 1不能使用implementation依赖项,但是可以使用(不建议使用)compile依赖项。
工作的build.gradle依赖项:

dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
....
}

关于spring-boot - Spring Boot 1和Gradle:ClassNotFoundException SpringApplicationBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64121664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com