简体   繁体   English

库 取决于 Spring 版本的集成应用程序

[英]Library Depending upon integrating application for Spring Version

So I am writing a library for some features and the inner library needs to use Spring .所以我正在为一些功能编写一个库,内部库需要使用Spring I don't want to put in the version of Spring in the inner library.我不想在内部库中Spring的版本。 I want that the application using the library defines the version of Spring to use.我希望使用该库的应用程序定义要使用的 Spring 的版本。

Is this even possible?这甚至可能吗? If yes, then how?如果是,那么如何?

Maven wise, clearly your library needs to be dependent on spring because it has to be compiled somehow so at least spring annotations like @Autowire or @Configuration / @Bean need to be in the compilation classpath. Maven 明智的,显然你的库需要依赖于 spring 因为它必须以某种方式编译,所以至少@Configuration需要在@Autowire或 @Autowire 类路径中@Bean注释。

However in the pom.xml of the library you can declare the dependency on spring as "optional" ( <optional>true</optional> )但是在库的pom.xml中,您可以将 spring 的依赖声明为“可选”( <optional>true</optional>

So when maven will compile the application that has your library as a dependency won't need to "take" transitively the spring as well因此,当 maven 将编译将您的库作为依赖项的应用程序时,也不需要“传递” spring

You can read about optional dependencies here .您可以在此处阅读有关可选依赖项的信息。 Their example with ProjectA, ProjectB and ProjectX is relevant...他们与 ProjectA、ProjectB 和 ProjectX 的示例是相关的......

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

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