Java Spring Boot不工作,出现一些错误?
请帮助我,因为我无法找出springboot应用程序中的问题。我正在使用以下pom.xmlJava Spring Boot不工作,出现一些错误?,java,spring,spring-boot,java-8,java-9,Java,Spring,Spring Boot,Java 8,Java 9,请帮助我,因为我无法找出springboot应用程序中的问题。我正在使用以下pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> <rela
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
<spring-boot-starter.version>2.22.0</spring-boot-starter.version>
<tomcat.version>9.0.37</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.2.2.RELEASE</version>
</dependency>
</dependencies>
当我使用tomcat 8时:
<tomcat.version>8.5.50</tomcat.version>
它是从以下位置加载的:
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:175)
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:/tomcat/embed/tomcat-embed-core/8.5.50/tomcat-embed-core-8.5.50.jar!/org/apache/tomcat/util/modeler/Registry.class
file:/tomcat/embed/tomcat-embed-core/8.5.50/tomcat-embed-core-8.5.50.jar
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry
如果有人知道如何解决这个问题,请帮助。我也遇到过类似的问题,原因是jsp api不适合相应的servlet api版本。正如Sven Döring已经提到的,Spring Boot 2.1.x使用Tomcat 9,它使用/提供Servlet API v4。为此,您需要JSPAPI 2.3.3,否则您可以得到NoSuchMethodError
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
有关版本匹配的更多信息,请参见:
不幸的是,此列表中缺少Tomcat 9和Servlet API 4。缺少的方法HttpServletRequest.getHttpServletMapping已添加到版本4中的Servlet API中,因此问题是由您对Servlet 3.1 API的依赖引起的: javax.servlet javax.servlet-api 3.1.0 假如
不需要声明对ServletAPI的依赖关系,因为它已经包含在SpringBootStarterWeb中。从pom.xml中删除上述内容应该可以解决您的问题。您的pom包含一些相互之间存在版本冲突的依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
及
因为这些是项目中的依赖项已经提供的可传递依赖项
您可以使用mvn dependency:tree-Dverbose检查依赖关系树并观察任何潜在的依赖关系冲突。已删除,但给出了相同的错误:javax.servlet.http.HttpServletRequest.getHttpServletMapping:是否会出现此错误?我不认为仍然。。。java.io.FileNotFoundException:.m2\repository\com\sun\xml\bind\jaxb core\2.3.0\jaxb-api.jarjaxb api不应该是问题。@shinjw建议运行mvn dependency:tree是一个很好的方法。这将让您了解Servlet API的其他来源,以及为什么在类路径上有它的旧版本。我尝试过只有一个javax.Servlet-API,它是4.0.1,但在eclipse中它显示为灰色,现在我正在使用java 9和tomcat 9,但sameserver仍能正常启动只是我在web浏览器中访问它时遇到的问题是,这帮助我解决了mvn依赖项:tree-Dverbose来找出问题:我删除了来自其中一个依赖项的javax.servlet-api 3.1.0,但在使用JSP时,我没有删除tomcat嵌入jasper
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>