java SDK支持diff spring版本
假设我计划开发一个SDK,这个SDK应该支持不同的spring版本,例如Spring2。x、 春天3。x和弹簧4。x、 SDK中只有很少的依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
一种方法是将${spring.version}设置为不同的版本,但这将导致大量的维护成本。 你知道这个问题吗
# 1 楼答案
首先,尽可能避免Spring依赖关系;例如,通常只需要为
@Component
注释包含spring-context
。假设可以避免前向不兼容,只需根据最早的兼容Spring进行构建。例如,为Spring 3.2编译的组件通常在Spring 4.3中加载时不会出现问题然而,如果有必要使用新的Spring版本的特性,最好的方法是完全创建一个新的工件。例如,当Thymeleaf需要使用仅在Spring 4中添加的功能时,it split into ^{} and ^{} 。这确实需要您付出更多的努力,但会让所有用户的构建和转换更加顺畅
# 2 楼答案
如果您打算在所有spring版本中使用几个具有相同签名的类和方法,我建议您查看Understanding Maven Version Numbers,特别是表表7-1版本范围参考。举个例子,当你看到版本[1.2,1.3]意味着1.2<;=x<;=1.3.
对于您的情况,您必须将属性“spring.version”调整为: