【发布时间】:2015-08-17 03:40:58
【问题描述】:
我正在开发一个基于 Spring Boot 的库,可以在多个 Spring Boot 应用程序中使用。该库应该可以与 Spring Boot 1.3.0.M1 一起使用。
我在考虑如何避免将特定版本的 Spring JAR 放入其中,而是让应用程序指定确切的版本。目前我已经提出了这个解决方案,除了某些组合之外,它似乎可以工作:
-
在库中,Spring Boot 版本为
1.3.0.M1,所有依赖的范围为provided。像这样:... <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.0.M1</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <scope>provided</scope> </dependency> ... -
在应用程序中,提及实际的 Spring Boot 版本,例如
1.3.0.M3,并重新包含所有依赖项,如下所示:... <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.0.M3</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> ...
当我使用这个 1.3.0.M1+1.3.0.M3 特定组合运行应用程序时,我收到了这个错误,我认为这只是一些兼容性问题:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.core.ResolvableType.forInstance(Ljava/lang/Object;)Lorg/springframework/core/ResolvableType;
但是,尝试稳定版本,例如当我将 lib 版本设置为 1.2.0.RELEASE 并将应用版本设置为 1.2.5.RELEASE 时,它可以工作。
所以,我想知道这是否是处理这种情况的正确方法,还是有更好的方法。
【问题讨论】:
-
如果你依赖 Spring Boot,那么几乎按照定义它不是一个库。
-
它的父级为
spring-boot-starter-parent,并有一些依赖关系,如spring-boot-starter-web。但是,它没有spring-boot-maven-plugin。因此,生成的是标准 JAR,而不是可执行 JAR。那为什么不能叫它库呢?
标签: spring maven spring-boot