【发布时间】:2019-03-22 08:48:12
【问题描述】:
我正在将在 tomcat 9 上运行良好的 springBoot 1.5 应用程序迁移到 SpringBoot 2。 当我尝试将其迁移到 pom 时
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
</dependency>
并更改一些必要的命名内容,我在启动 tomcat9 或 tomcat 8.5 时得到此输出:
17:39:39.590 [RMI TCP Connection(3)-127.0.0.1] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
(...)
17-Oct-2018 17:39:39.591 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/policyManagement]]
(...)
Caused by: java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
(...)
17-Oct-2018 17:39:39.597 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.tomcat.util.modeler.BaseModelMBean.invoke Exception invoking method manageApp
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/policyManagement]]
(...)
[2018-10-17 05:39:39,612] Artifact policyManagement-web:war exploded: Error during artifact deployment. See server log for details.
(...)
17-Oct-2018 17:39:39.598 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.tomcat.util.modeler.BaseModelMBean.invoke Exception invoking method createStandardContext
javax.management.RuntimeOperationsException: Exception invoking method manageApp
(...)
Caused by: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/policyManagement]]
(...)
我尝试将-Xms256m -Xmx2048m 添加到Tomcat VM Options
或在 SpringBoot 上尝试<version>2.1.0.M4</version> 或<version>2.0.5</version>
编辑:
我在课堂上有这段代码注释@SpringBootApplication:
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Z.class);
}
如何更改?
来自这个应用程序的 Pom:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>Z</groupId>
<artifactId>X</artifactId>
<version>4.6.0-SNAPSHOT</version>
</parent>
<artifactId>X</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
(and some standard-dependencies)
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifestEntries>
<Sys-Version>${project.version}</Sys-Version>
<!-- Variables set by Hudson -->
<Build-Number>${BUILD_NUMBER}</Build-Number>
<Build-Date>${BUILD_TIMESTAMP}</Build-Date>
<!-- Next two for potential usage in the next AppInfo versions -->
<Job-Name>${JOB_NAME}</Job-Name>
<Git-Branch>${GIT_BRANCH}</Git-Branch>
<Git-Commit>${GIT_COMMIT}</Git-Commit>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.5.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- Enable this profile to run in IntelliJ. IntelliJ excludes provided dependencies from compile by default. -->
<id>intellij</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
来自其父级的 Pom:
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>A</groupId>
<artifactId>parent</artifactId>
<version>4.6.0-SNAPSHOT</version>
</parent>
<artifactId>A</artifactId>
<packaging>pom</packaging>
<modules>
<module>X</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Edgware.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
将一些名称更改为 X、Y、A 等。
在这里,我尝试在 default 配置文件上的 tomcat 上运行它。
编辑:
我认为我需要将<version>Edgware.SR4</version> 更改为Finchley.RELEASE
【问题讨论】:
-
您有一些代码正在调用与 Spring Boot 2.0 不兼容的
SpringApplicationBuilder的构造函数。在 1.5 中,它的签名是public SpringApplicationBuilder(Object... sources),在 2.0 中,它的签名是public SpringApplicationBuilder(Class<?>... sources)。我不知道该代码是什么,因为您没有在问题中包含NoSuchMethodError的堆栈跟踪。 -
@AndyWilkinson 我无法输入完整的堆栈跟踪,导致 StackOverflow 警告问题是大多数代码。我将尝试检查(在代码中找到这个 SpringApplicationBuilder)并明天添加更多堆栈跟踪。谢谢。
-
@AndyWilkinson 我编辑了添加有关
SpringApplicationBuilder的代码的问题,我如何更改它以使其工作?这部分在编译时不会失败 -
为什么要在tomcat下运行?为什么不干脆用码头作为容器建造一个独立的(胖)罐子,然后把tomcat留在路边(我在过去的5年里一直这样做)。你只需运行 jar 和瞧,不再需要 Tomcat 配置 BS。
-
@Bohemian 因为这个项目目前在标准 springBoot 运行下无法运行。它仅适用于tomcat。我不知道为什么在技术上。客户仍然使用 tomcat - 不是罐子 - 这就是为什么 - 如果我们谈论业务。
标签: java spring-boot tomcat