英文:
Unable to exclude DataSourceAutoConfiguration class while running fat jar from cmd
问题
以下是我的Spring Boot主类配置:
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@Configuration
@EnableAutoConfigurationProperties
public class MainClass{
}
当我在IntelliJ中运行这个Spring Boot应用时,它不会抛出任何错误。但是,当我使用以下方式导出fat jar后:
build.gradle >>>
jar {
manifest {
attributes {
//主类
}
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
命令行输出如下:
以下类无法排除,因为它们不是自动配置类:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
请问有人可以帮助我理解在命令行运行时我漏掉了什么吗?
我尝试在创建fat jar时排除了 "META-INF/.SF"、"META-INF/.DSA" 和 "META-INF/*.RSA",但问题仍然存在。
英文:
Below is my spring boot main class configuration :
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@Configuration
@EnableAutoConfigurationProperties
public class MainClass{
}
When i am running this spring boot using intellij, it doesn't throw any error but after i had exported the fat jar using the following :
build.gradle >>>
jar{
manifest{
attributes{
//main class
}
}
from{
configurations.runtimeClasspath.collect{it.isDirectory()? it : zipTree(it)}
}
}
the cmd output says :
The following classes could not be excluded because they are not auto-configurable classes:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Can someone please help me understand what I am missing while running through cmd?
I tried excluding "META-INF/.SF", "META-INF/.DSA" , "META-INF/*.RSA" while creating the fat jar but the issue still persists.
答案1
得分: 0
不需要自己构建fatjar。Spring Boot已经为您处理了。
删除您的自定义jar任务,并确保您的插件列表中包含Spring Boot插件。
plugins {
id 'org.springframework.boot' version '3.1.1'
}
或者您的版本是什么。
然后在运行./gradlew build
或gradle build
时,生成的构件已经是一个fatjar和可运行的jar。您不需要进行任何额外的工作。
英文:
You don't need to build a fatjar yourself. Spring Boot already handles that for you.
Remove your custom jar task and make sure you have the Spring Boot plugin in yuour list of plugins.
plugins {
id 'org.springframework.boot' version '3.1.1'
}
Or whatever your version is.
Then when running ./gradlew build
or gradle build
the resulting artifact will already be a fatjar and runnable jar. You don't need to do any additional work for that.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论