简体   繁体   English

Spring 引导:从外部 Jar 文件引入配置类

[英]Spring Boot: Bring In Configuration Classes From External Jar File

I'm trying to reduce the amount of "copy/paste" code I have across multiple Spring projects, such as a custom WebSecurityConfigurerAdapter.我正在尝试减少跨多个 Spring 项目(例如自定义 WebSecurityConfigurerAdapter)的“复制/粘贴”代码量。 This adapter is the exact same code across all projects I have so far, so normally in these situations I create a standalone code base and export to a jar to keep things maintainable.这个适配器是我迄今为止所有项目中的完全相同的代码,所以通常在这些情况下,我创建一个独立的代码库并导出到 jar 以保持可维护性。

The issue is that it seems that when I do that, Spring no longer notices that class as one that it needs to ingest into it's auto configuration, as when I removed that security class from my project and brought in the jar library now containing it, the security feature I developed was broken. The issue is that it seems that when I do that, Spring no longer notices that class as one that it needs to ingest into it's auto configuration, as when I removed that security class from my project and brought in the jar library now containing it,我开发的安全功能被破坏了。 Undid that change and it was working again.撤消该更改,它又可以正常工作了。

Is there any way that I can tell Spring to look at specific jar files to ingest into it's configuration so that I can keep myself from having classes upon classes of configuration code that's ultimately repeated across multiple projects?有什么方法可以告诉 Spring 查看特定的 jar 文件以摄取到它的配置中,这样我就可以防止自己在最终在多个项目中重复的配置代码类上进行分类?

You can use the @ComponentScan annotation with arguments in your application class to point to multiple modules.您可以在应用程序 class 中将 @ComponentScan 注释与 arguments 一起使用以指向多个模块。 It is explained here .在这里解释。 This will override the default one included in @SpringBootApplication这将覆盖 @SpringBootApplication 中包含的默认值

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

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