【发布时间】:2023-03-25 07:44:01
【问题描述】:
刚开始一个简单的项目,当尝试使用简单的索引页面运行 Docker 容器时,使用 mvn spring-boot:build-image 命令进行构建,我收到以下错误。
不确定这是 Tomcat 还是 Spring 问题?在 SO 上只发现了一个类似的问题,这与不兼容版本的混合有关,但在这种情况下,我很确定所有 pom 都是最新的。我还尝试了一个没有 Undertow 但响应相同的构建。
在网上没有找到任何类似的问题。另外,注意它在 Intellij 中启动时运行良好,只有在 dockerized 时才会失败。
silenceisgrand | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
silenceisgrand | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
silenceisgrand | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
silenceisgrand | ' |____| .__|_| |_|_| |_\__, | / / / /
silenceisgrand | =========|_|==============|___/=/_/_/_/
silenceisgrand | :: Spring Boot :: (v2.3.2.RELEASE)
silenceisgrand |
silenceisgrand | 2020-11-09 09:01:15,366 INFO [main] org.springframework.boot.StartupInfoLogger: Starting SilenceisgrandApplication v0.0.1 on fd30e9598f54 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
silenceisgrand | 2020-11-09 09:01:15,367 INFO [main] org.springframework.boot.SpringApplication: The following profiles are active: h2o
silenceisgrand | 2020-11-09 09:01:15,723 INFO [main] org.springframework.data.repository.config.RepositoryConfigurationDelegate: Bootstrapping Spring Data JPA repositories in DEFERRED mode.
silenceisgrand | 2020-11-09 09:01:15,758 INFO [main] org.springframework.data.repository.config.RepositoryConfigurationDelegate: Finished Spring Data repository scanning in 29ms. Found 2 JPA repository interfaces.
silenceisgrand | 2020-11-09 09:01:16,037 WARN [main] org.springframework.context.support.AbstractApplicationContext: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoSuchMethodError: 'org.apache.coyote.ProtocolHandler org.apache.coyote.ProtocolHandler.create(java.lang.String, boolean)'
silenceisgrand | 2020-11-09 09:01:16,044 INFO [main] org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener:
silenceisgrand |
silenceisgrand | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
silenceisgrand | 2020-11-09 09:01:16,045 ERROR [main] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter:
silenceisgrand |
silenceisgrand | ***************************
silenceisgrand | APPLICATION FAILED TO START
silenceisgrand | ***************************
silenceisgrand |
silenceisgrand | Description:
silenceisgrand |
silenceisgrand | An attempt was made to call a method that does not exist. The attempt was made from the following location:
silenceisgrand |
silenceisgrand | org.apache.catalina.connector.Connector.<init>(Connector.java:87)
silenceisgrand |
silenceisgrand | The following method did not exist:
silenceisgrand |
silenceisgrand | 'org.apache.coyote.ProtocolHandler org.apache.coyote.ProtocolHandler.create(java.lang.String, boolean)'
silenceisgrand |
silenceisgrand | The method's class, org.apache.coyote.ProtocolHandler, is available from the following locations:
silenceisgrand |
silenceisgrand | jar:file:/workspace/BOOT-INF/lib/tomcat-coyote-10.0.0-M8.jar!/org/apache/coyote/ProtocolHandler.class
silenceisgrand | jar:file:/workspace/BOOT-INF/lib/tomcat-embed-core-9.0.37.jar!/org/apache/coyote/ProtocolHandler.class
silenceisgrand |
silenceisgrand | The class hierarchy was loaded from the following locations:
silenceisgrand |
silenceisgrand | org.apache.coyote.ProtocolHandler: file:/workspace/BOOT-INF/lib/tomcat-coyote-10.0.0-M8.jar
silenceisgrand |
silenceisgrand |
silenceisgrand | Action:
silenceisgrand |
silenceisgrand | Correct the classpath of your application so that it contains a single, compatible version of org.apache.coyote.ProtocolHandler
而且 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 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.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.silenceisgrand</groupId>
<artifactId>silenceisgrand</artifactId>
<version>0.0.1</version>
<name>silenceisgrand</name>
<description>The core silenceisgrand.com site</description>
<properties>
<java.version>11</java.version>
<webjars-bootstrap.version>4.5.3</webjars-bootstrap.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<!-- Undertow; replacing Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- webjars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
<version>0.46</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery-ui</artifactId>
<version>1.12.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>${webjars-bootstrap.version}</version>
</dependency>
<!-- Hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<!-- Thymeleaf java8time extras -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
-
你正在混合不同版本的 spring boot/spring...
-
不确定我在哪里混合版本?将设置设置 Undertow 设置为 2.3.2 甚至删除它不会改变任何东西......对不起,困惑
-
您正在使用 spring-boot-starter-undertow:2.3.4.RELEASE 但您的父版本是 2.3.2.RELEASE 此外,您正在使用版本 5.4.0 定义 spring-security-test。我强烈建议使用 spring-boot 父级定义的版本,而不是覆盖这些版本。也移动到最新版本的spring-boot-parent 2.3.5.RELEASE ...
-
@khmarbaise 非常感谢!我确实没有意识到父版本低于 Undertow。我拿走了所有与 spring boot 相关的本地版本标签,清理了 maven 项目,删除了缓存并重新构建了项目。现在它可以正常工作了。很明显,我必须阅读 maven poms 的父子关系。非常感谢您的帮助!!
标签: java spring spring-boot maven tomcat