简体   繁体   English

从其他应用程序启动Spring Boot App

[英]Start Spring Boot App from other application

I have a java application and a Spring Boot application. 我有一个Java应用程序和一个Spring Boot应用程序。 I want to MySpringBootApp.run() and MySpringBootApp.hereYouHaveSomeInfo() , so I want to call methods of the Spring Boot App but Spring Boot kind of processes my class and renames it, so I get a ClassNotFoundException in the other App. 我想要MySpringBootApp.run()MySpringBootApp.hereYouHaveSomeInfo() ,所以我想调用Spring Boot App的方法,但是Spring Boot会处理我的类并重命名它,所以我在另一个App中得到了ClassNotFoundException。

Thanks for you help! 感谢您的帮助!

If I understand you correctly, you are building the executable version of the spring boot application. 如果我对您的理解正确,那么您正在构建Spring Boot应用程序的可执行版本。

This jar file cannot be used as a dependency. 此jar文件不能用作依赖项。

You need to build the classical jar file without the dependencies and add this to your application's dependency list. 您需要构建没有依赖项的经典jar文件,并将其添加到应用程序的依赖项列表中。

I suppose you build with maven . 我想你是用maven建立的。 The target folder will contain two files: target文件夹将包含两个文件:

  • a yourapp-<version>.jar and 一个yourapp-<version>.jar
  • a yourapp-<version>.jar.original which is substanially smaller. 一个yourapp-<version>.jar.original ,它实际上较小。

The .jar File is not suitable for inclusion as a dependency. .jar文件不适合作为依赖项包含在内。 You need the .original file. 您需要.original文件。 I suggest, if you need both, that you setup a project creating the .original file as regular .jar target, without the spring-boot plugin. 我建议,如果两者都需要,请设置一个项目,将.original文件创建为常规.jar目标,而没有spring-boot插件。 And you add another project, with the spring-boot plugin, that requires the "simple" .jar file as dependency and has the spring-boot plugin enabled. 然后,添加另一个带有spring-boot插件的项目,该项目需要“ simple” .jar文件作为依赖项并启用了spring-boot插件。

Your second application will also list the "simple" jar file as a dependency, the fat jar can be delivered as usual. 您的第二个应用程序还将列出“简单”的jar文件作为依赖项,胖jar可以照常交付。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM