无法在从命令行运行的fat jar中排除DataSourceAutoConfiguration类。

huangapple go评论59阅读模式
英文:

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 buildgradle 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.

huangapple
  • 本文由 发表于 2023年7月13日 15:18:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定