SpringBoot整合SpringCloud报错,父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> <!--使用Spring Boot应用的父级依赖 好处:引入父pom里的依赖时无须指定版本 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.12.RELEASE</version> <!--SB和SC版本对应关系:https://spring.io/projects/spring-cloud--> </parent> <groupId>com.lhy</groupId> <artifactId>cloud-doc</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>doc-service-ucenter</module> <module>doc-service-api</module> <module>doc-service-atlas</module> <module>doc-service-order</module> <module>doc-service-search</module> <module>doc-govern-gateway</module> <module>doc-govern-register</module> </modules> <properties> <java.version>1.8</java.version> <tomcat.version>8.5.28</tomcat.version> <spring-cloud.version>Hoxton.SR9</spring-cloud.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> </dependency> </dependencies> </dependencyManagement> </project>
启动子项目报错:
2022-04-03 20:48:12.143 INFO 25812 --- [ main] c.l.d.r.DocGovernRegisterApplication : No active profile set, falling back to default profiles: default
2022-04-03 20:48:12.753 WARN 25812 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2022-04-03 20:48:12.853 INFO 25812 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=4f72d5e5-5584-3bcc-ad5c-7a9176d1d0cf
2022-04-03 20:48:13.020 WARN 25812 --- [ main] ConfigServletWebServerApplicationContext : 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.tomcat.util.modeler.Registry.disableRegistry()V
2022-04-03 20:48:13.032 INFO 25812 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-04-03 20:48:13.045 ERROR 25812 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:177)
The following method did not exist:
org.apache.tomcat.util.modeler.Registry.disableRegistry()V
The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:
jar:file:/D:/mvnrepository/org/apache/tomcat/embed/tomcat-embed-core/8.5.28/tomcat-embed-core-8.5.28.jar!/org/apache/tomcat/util/modeler/Registry.class
The class hierarchy was loaded from the following locations:
org.apache.tomcat.util.modeler.Registry: file:/D:/mvnrepository/org/apache/tomcat/embed/tomcat-embed-core/8.5.28/tomcat-embed-core-8.5.28.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry
还以为SpringBoot和SpringCloud版本不匹配呢,去https://spring.io/projects/spring-cloud 看了发现版本匹配:
最后发现是properties中写了tomcat版本8.2.28 ,删除这个即可,spring-boot-starter-parent中的tomcat版本是
<tomcat.version>9.0.46</tomcat.version>