Java 添加依赖项时,SpringBoot应用程序启动失败
我有一个现有的SpringBoot应用程序,运行时没有问题。然后我创建了一个Java库——一个只有静态Java代码,没有主类的独立存储库。我的库作为GitHub Maven包部署 然后,我继续在本地Maven设置中设置GitHub包存储库,并将依赖项添加到原始SpringBoot应用程序中。导入过程成功,我的库的Jar位于类路径中,编译和构建成功 接下来要做的是,我现在运行应用程序,并获得以下stacktrace:Java 添加依赖项时,SpringBoot应用程序启动失败,java,spring-boot,maven,github-package-registry,Java,Spring Boot,Maven,Github Package Registry,我有一个现有的SpringBoot应用程序,运行时没有问题。然后我创建了一个Java库——一个只有静态Java代码,没有主类的独立存储库。我的库作为GitHub Maven包部署 然后,我继续在本地Maven设置中设置GitHub包存储库,并将依赖项添加到原始SpringBoot应用程序中。导入过程成功,我的库的Jar位于类路径中,编译和构建成功 接下来要做的是,我现在运行应用程序,并获得以下stacktrace: 02:36:51.110 [main] DEBUG org.springfram
02:36:51.110 [main] DEBUG org.springframework.boot.context.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [<redacted list of classpath dependencies, including my new library>]
02:36:51.223 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:102)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:68)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at my.org.transfer.TransferServicesApiApplication.main(TransferServicesApiApplication.java:18)
Process finished with exit code 1
我的库的pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>my.org</groupId>
<artifactId>appname</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency> <!-- my library import -->
<groupId>my.org</groupId>
<artifactId>mylibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.6</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-booter</artifactId>
<version>2.22.2</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<goalPrefix>formatter</goalPrefix>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.12.0</version>
</plugin>
</plugins>
</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>my.org</groupId>
<artifactId>mylibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<distributionManagement>
<repository>
<id>github</id>
<name>Github Packages</name>
<url>https://maven.pkg.github.com/my-org/library-repo</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
<version>1.11.793</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-secrets-manager-config</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.12.0</version>
</plugin>
</plugins>
</build>
</project>
您正在使用不同版本的spring boot starter父版本(2.3.1.RELEASE和2.3.4.RELEASE),这可能会导致版本不一致,而更高版本或更早版本没有此方法。尝试在应用程序中使用2.3.4.RELEASE [更新] 您仍然在类路径上看到不一致的
org.springframework:
:
[INFO] | \- org.springframework:spring-webmvc:jar:5.2.9.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.2.9.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.2.9.RELEASE:compile
...
[INFO] +- org.springframework:spring-web:jar:5.2.7.RELEASE:compile
在应用程序pom.xml中,从
org.springframework
关于要求特定版本的Spring Boot和最新版本的Spring cloud aws secrets manager配置是2.2.4.RELEASE
,这使我认为您库的POM需要更新以使用最新版本。您使用的是不同版本的Spring Boot starter父版本(2.3.1.RELEASE和2.3.4.RELEASE)这可能会导致不一致的版本,而更高版本或更早版本没有该方法。尝试在应用程序中使用2.3.4.RELEASE
[更新]
您仍然在类路径上看到不一致的org.springframework:
:
[INFO] | \- org.springframework:spring-webmvc:jar:5.2.9.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.2.9.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.2.9.RELEASE:compile
...
[INFO] +- org.springframework:spring-web:jar:5.2.7.RELEASE:compile
在应用程序pom.xml中,从
org.springframework
关于要求特定版本的Spring Boot和最新版本的Spring cloud aws secrets manager config
是2.2.4。发布版
,这使我认为您的库的POM需要更新以使用最新版本。很抱歉--我建议您尝试在项目中运行mvn dependency:tree
,看看是否可以获取可能存在版本冲突的线索。将输出添加到问题中--太长,无法发表评论。在阅读您的更新之前,我刚刚检查了spring cloud aws secrets manager配置
版本。这使得应用程序引导稍微进一步,但未能使用springweb
依赖项初始化bean。按照你的建议删除了那个版本,效果很好!谢谢!很抱歉--我建议您尝试在项目中运行mvn dependency:tree
,看看您是否能找到可能存在版本冲突的线索。在问题中添加了输出--太长,无法发表评论。在阅读您的更新之前,我刚刚检查了spring cloud aws secrets manager配置
版本。这使得应用程序引导稍微进一步,但未能使用springweb
依赖项初始化bean。按照你的建议删除了那个版本,效果很好!谢谢!另外,请注意,您不需要单独指定springweb
依赖项。spring boot starter web为您提供了这种依赖性。此外,您不需要定义lombok、commons codec和commons-lang3的版本。它们由Spring Boot为您解决。优点是升级Spring引导依赖项时,这些依赖项将自动更新。另外,请注意,不需要单独指定Spring web
依赖项。spring boot starter web为您提供了这种依赖性。此外,您不需要定义lombok、commons codec和commons-lang3的版本。它们由Spring Boot为您解决。优点是当您升级Spring引导依赖项时,这些依赖项将自动更新。