spring-boot团队的人员你们好:

Hello, spring boot team:

最近构建了一个javafx项目做测试遇到了无法解决的问题,在互联网中查找了很多相关的问题,包括当前github上相关问题也都查看但并不能解决实际问题,希望能给与帮助或参考.

Recently, I built a javafx project for testing and encountered problems that cannot be solved. I found many related problems on the Internet, including the current github related problems, but they cannot solve the actual problems. I hope you can give me help or reference

问题详细描述:

Detailed description of the problem:

  1. 项目环境:springboot 2.7.4 +JavaFx17(springboot-javafx-support JDK17自编译无任何修改)

  2. Project environment: spring boot 2.7.4+JavaFx17 (spring boot javafx support JDK17 self compiled without any modification)

  3. 测试方法:

  4. Test method:

1). idea 完全能正常运行(OK)

1). Idea can operate normally (OK)

2).mavn clean install 打包jar 运行异常.(无法加载spring boot 自动配置相关)

2). The mavn clean install package jar runs abnormally (Unable to load spring boot auto configuration related)

3). mvn spring-boot:run(OK)

3). mvn spring-boot:run(OK)

  1. 运行异常信息:

  2. Abnormal operation information: java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories nor in META-INF/spring/org.springframework.boot.a utoconfigure.AutoConfiguration.imports. If you are using a custom packaging, make sure that file is correct. at org.springframework.util.Assert.notEmpty(Assert.java:470) at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:185) at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getAutoConfigurationEntry(AutoConfigurationImportSelector.java:125) at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector$AutoConfigurationGroup.process(AutoConfigurationImportSelector.java: ......

4.构建与查询相关资料汇总说明:

  1. Summary description of construction and query related data:

在其他人提问的问题中找到一个相关问题,但是只做了相关说明与关闭问题并没有见到实际的解决方法,本问题是springboot加载提供的自动配置信息错误产生的(spring-boot-actuator-autoconfigure-2.7.4.jar),在IDEA或mvn spring-boot:run中测试可以加载到configurations数据,但是打包jar文件后运行加载不到configurations配置信息,即spring.factories(org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration.imports),也参考了spring-boot-maven-plugin文档,没任何效果,打包后就是获取不到自动配置信息,非常奇怪,在以前版本例如(springboot+javafx(jdk8))没有遇到这样的问题.

I found a related problem among the questions asked by others, but only made relevant explanations and did not see an actual solution to the problem. This problem is caused by an error in the automatic configuration information provided by spring boot loading (spring boot actor autoconfigure-2.7.4. jar). Testing in IDEA or mvn spring boot: run can load the configurations data, but the configuration information cannot be loaded after the jar file is packaged, That is, spring. factories (org. springframework. boot. act. autoconfigure. web. ManagementContextConfiguration. imports)I also referred to the spring boot maven plugin document, which has no effect. After packaging, I just can't get the automatic configuration information. It's very strange. In previous versions, such as (spring boot+javafx (jdk8)), I didn't encounter such problems.

Comment From: wilkinsona

It sounds like your jar's not being packaged correctly. Perhaps you're using Maven's Shade plugin and the META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports files are not being merged together?

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: liangchaos

dome

Comment From: wilkinsona

That's an archive of JavaFX source code which is not what we need. Please provide a minimal Spring Boot application that we can build and run to reproduce the problem.

Comment From: liangchaos

No, 不是这样的

No, that's not true

项目中有三个文件:

There are three files in the project:

  1. jar-test-springboot2.7.4:就是打包有异常的异常项目, idea 运行和mvn spring-boot:run 两种方式运行正常, 打包后的jar,就无法运行,产生No auto configuration classes found in META-INF/spring.factories nor in META-INF/spring/org.springframework.boot.a

  2. jar test springboot2.7.4: It refers to the abnormal items packed with exceptions. The idea runs normally and the mvn spring boot: run runs normally. The packed jar cannot run. No auto configuration classes found in META-INF/spring is generated factories nor in META-INF/spring/org.springframework.boot.a

utoconfigure.AutoConfiguration.imports. If you are using a custom packaging, make sure that file is correct.异常, 无法打包执行.

utoconfigure.AutoConfiguration.imports. If you are using a custom packaging, make sure that file is correct. Exception, unable to package and execute

  1. javafx-sdk-19.rar: 是项目需要的sdk, jdk13 以后javafx已经独立出来了,没有javafx sdk 无法启动.

  2. javafx sdk-19. rar: it is the sdk required by the project. Since jdk13, javafx has been independent, and cannot be started without javafx sdk

  3. README.txt :配置说明

  4. README. Txt: Configuration description

Comment From: liangchaos

在问题中看到有类似的情况,但是没有见到解决方法

I saw a similar situation in the problem, but I didn't see a solution

Cannot Kotlin bootRun on Windows due to long paths / No auto configuration classes found in META-INF/spring.factories #14262

Comment From: wilkinsona

As far as I can tell, the git repo you have shared contains a single file. The file is named jar-test-springboot.rar. I am on macOS so I cannot extract it. Listing its contents shows that it only contains JavaFX source files. If there are other files in the rar I cannot see them. Can you please extract the rar's contents and check them into the git repository?

Comment From: liangchaos

It has been updated and decompressed. First of all, thank you for your help

Comment From: wilkinsona

There's a bug in the code that's launching the Spring Boot application which means that the thread context class loader is the app class loader rather than Spring Boot's class loader. You can fix it like this:

CompletableFuture.supplyAsync(() -> {
    Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
    return SpringApplication.run(this.getClass(), savedArgs);
})

If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

Comment From: liangchaos

ok 非常感谢你的帮助,问题解决了,非常非常感谢你的帮助!!!

Ok Thank you very much for your help. The problem has been solved. Thank you very much for your help!!!

Comment From: zoe610

请问如果spring.factories文件没有打到jar包里,需要做什么配置? What should I do when I use maven install but without spring.factories, other codes are correct

Comment From: wilkinsona

@zoe610 We prefer to handle questions on Stack Overflow or Gitter.

Comment From: cfnz

Thank you @wilkinsona !

There's a bug in the code that's launching the Spring Boot application which means that the thread context class loader is the app class loader rather than Spring Boot's class loader. You can fix it like this:

java CompletableFuture.supplyAsync(() -> { Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); return SpringApplication.run(this.getClass(), savedArgs); })

I didn't have the Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); line in my code, and it was causing me great confusion as it ran on my box, and on other boxes, but not on all other boxes... for some unknown reason (Java versions and as much as possible else all the same) it worked on some and not others...

Came across this post and tried it out, and it fixed my issue... just posting here as the intermittent (repeatable on the same box, bot not on all PCs) nature issue is what slowed me down.