简体   繁体   English

在没有@ComponentScan 和 Xml 配置的情况下将 spring boot jar 导入另一个应用程序

[英]Importing spring boot jar into another app without @ComponentScan and Xml Configurations

I'm looking for a generic/clean solution to import a spring boot jar application into another spring boot application without doing @ComponentScan(package name of the application), without the xml configuration.我正在寻找一种通用/干净的解决方案,将 spring boot jar 应用程序导入另一个 spring boot 应用程序,而无需执行 @ComponentScan(应用程序的包名称),无需 xml 配置。

If I didn't say @Componentscan in the base application, @Autowired is not working, which is quite understandable.如果我没有在基础应用程序中说@Componentscan,@Autowired 不起作用,这是可以理解的。

So in general writing libraries with spring boot is not a ideal way?所以一般来说用 spring boot 编写库不是一个理想的方式吗?

Finally, I went with @Import(ApplicationConfiguration)which I find it quite neat.最后,我选择了 @Import(ApplicationConfiguration),我觉得它很简洁。

I had a multi-level project structure so on each of the sub-module created a configuration file which initiate the required beans and then in the parent module, I have used @Import.我有一个多级项目结构,所以每个子模块都创建了一个配置文件来启动所需的 bean,然后在父模块中,我使用了 @Import。

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

相关问题 Spring 引导:ComponentScan 与自动配置的 Jar 中声明的 Bean - Spring Boot: ComponentScan vs Declared Bean in an Autoconfigured Jar Spring boot 不运行 ComponentScan - Spring boot not run ComponentScan 如何在不使用 Spring Boot 的情况下使用 Hibernate .xml 配置注入 Spring Data JPA? - How to inject Spring Data JPA with Hibernate .xml configurations but without using Spring Boot? Spring boot ComponentScan excludeFIlters 不排除 - Spring boot ComponentScan excludeFIlters not excluding Spring 引导 @ComponentScan 与 @Import - Spring boot @ComponentScan vs @Import 如何从spring boot项目创建jar,我们要在另一个spring boot应用中使用的jar? - how to create jar from spring boot project , this jar we want to use in another spring boot app? 在另一个项目中运行 spring 引导而不使用 @SpringBootApplication 注释作为 jar 库 - Run spring boot without @SpringBootApplication annotation as jar library in another project 如何在Spring Boot中使用@ComponentScan从jar和类似默认值的通配符加载类? - How use @ComponentScan in Spring Boot to load classes from jar and a wildcard that works like the default? Spring Boot - Spring 安全 @ComponentScan 或 @Import - Spring Boot - Spring security @ComponentScan or @Import Junit5 Spring Boot Autowire ComponentScan 不工作 - Junit5 Spring Boot Autowire ComponentScan Not Working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM