스프링 부트: java.lang.NoSch Method Error: javax.servlet.http.Http ServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
내장 서버 또는 다른 Tomcat 서버에서 이 응용 프로그램을 실행하면 다음 오류 메시지가 나타납니다.jdk8, STS V-3.9.7을 사용하고 있습니다.누가 해결 좀 도와줄래?
심플한 Springboot 어플리케이션.내용은 다음과 같습니다.
뷰 매핑용 application.properties 파일
spring.mvc.view.prefix=/WEB-INF/jspViews/
spring.mvc.view.suffix=.jsp
index.jsp
<body>
<h3>Application is working</h3>
</body>
컨트롤러 클래스
@Controller
public class AppController {
@RequestMapping("/")
public String indexPage() {
return "index";
}
}
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>ehospitalsso</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
web.xml 파일
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
<display-name>demo</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
오류 StackTrace ::
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
at org.apache.catalina.core.ApplicationHttpRequest.setRequest(ApplicationHttpRequest.java:690) ~[catalina.jar:na]
at org.apache.catalina.core.ApplicationHttpRequest.<init>(ApplicationHttpRequest.java:114) ~[catalina.jar:na]
at org.apache.catalina.core.ApplicationDispatcher.wrapRequest(ApplicationDispatcher.java:917) ~[catalina.jar:na]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:358) ~[catalina.jar:na]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) ~[catalina.jar:na]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:170) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:na]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-websocket.jar:9.0.13-dev]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:na]
at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:130) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:66) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:105) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:123) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:na]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:na]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [catalina.jar:na]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:na]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [catalina.jar:na]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [catalina.jar:na]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [catalina.jar:na]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) [catalina.jar:na]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:na]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:na]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-coyote.jar:9.0.13-dev]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:9.0.13-dev]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) [tomcat-coyote.jar:9.0.13-dev]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-coyote.jar:9.0.13-dev]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:9.0.13-dev]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_161]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_161]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.13-dev]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_161]
화면 정렬:
친절히 참석해주세요.업데이트 pox.xml 파일용 Avijit
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
</parent>
<groupId>com.demo</groupId>
<artifactId>Demo_App</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Demo_App</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
ServletInitializer 클래스
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoAppApplication.class);
}
}
Demo App Application 클래스
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoAppApplication {
public static void main(String[] args) {
SpringApplication.run(DemoAppApplication.class, args);
}
}
Spring Boot에 버전 미스매치(Bug?일 가능성이 있음)가 있는 것 같습니다.
Spring Boot 2.1.X는 Servlet API v4를 갖춘 Tomcat 9를 사용합니다.
그러나 Spring Boot Web 2.1.X에는 여전히 Servlet API v3.1이 포함되어 있습니다.
이 문제를 해결하려면 spring-boot-starter-tomcat을 버전 2.0.X로 다운그레이드해야 합니다.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.0.7.RELEASE</version>
<scope>test</scope>
</dependency>
편집:
Tomcat 버전 속성만 변경하면 됩니다.
<properties>
<tomcat.version>8.5.37</tomcat.version>
<properties>
비슷한 문제가 있었는데 jsp-api가 대응하는 servlet-api 버전에 맞지 않았기 때문입니다.Sven Döring이 이미 언급했듯이 Spring Boot 2.1.x는 Servlet API v4를 사용하거나 제공하는 Tomcat 9를 사용합니다.이를 위해서는 jsp-api 2.3.3이 필요합니다.그렇지 않으면 NoSch Method Error를 얻을 수 있습니다.
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
버전 일치에 대한 자세한 내용은 다음을 참조하십시오.유감스럽게도 최종 Java 버전 테이블(J2EE, Java EE, Servlet, JSP, JSTL)은 이 목록에 없습니다.
gradle용 Sven Döring 솔루션의 답변에 추가하겠습니다.
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springVer) {
exclude module: "spring-boot-starter-tomcat"
}
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: springTomcatVer)
이 시점에서 파라미터를 설정합니다.
springVer='2.1.8.해방'
springTomcatVer='2.0.9'해방'
다음과 같이 DemoApp Application을 서블릿 이니셜라이저와 병합합니다.
@SpringBootApplication
public class DemoAppApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(DemoAppApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoAppApplication.class);
}
}
또는 추가@Configuration
확장되는 클래스에 대한 주석SpringBootServletInitializer
아래 픽스는 나를 위해 작동했다.고마워 스벤 도링
<properties>
<tomcat.version>8.5.37</tomcat.version>
<properties>
servlet-api 버전이 Tomcat 버전과 일치하지 않기 때문입니다.Tomcat 9.x를 사용하는 경우 v4를 통해 servlet-api 버전을 확인해야 합니다. 또한 Tomcat 8.x는 servlet-api v3를 사용해야 합니다.
위의 제안에도 불구하고 여전히 교착상태에 빠져 있는 사용자:
제 문제는 다음을 포함했기 때문입니다.javax.servlet:javax.servlet-api:3.1.0
내 안에서build.gradle
파일 의존성(단, 같은 문제가 maven에서도 발생할 수 있습니다).
Tomcat을 경우, 「Tomcat」는, 「Tomcat」를 참조해 주세요.javax
에 포함되어 .tomcat-embed-core
에 spring-boot-starter-tomcat
에 대한 합니다.javax.servlet:javax.servlet-api:3.1.0
.
apache-tomcat-9.0.27\lib\servlet_api.jar에서 project lib 경로에 servlet_api.jar를 추가하여 문제를 해결했습니다.
언급URL : https://stackoverflow.com/questions/54122724/spring-boot-java-lang-nosuchmethoderror-javax-servlet-http-httpservletrequest
'source' 카테고리의 다른 글
React-Router v4를 통한 값 전달 (0) | 2023.02.17 |
---|---|
캔 어 앵글JS 컨트롤러는 같은 모듈의 다른 컨트롤러로부터 상속받습니까? (0) | 2023.02.17 |
WooCommerce - 다운로드 가능한 구매에 대한 배송 비활성화 (0) | 2023.02.13 |
모든 모델 클래스에 JSON 시리얼라이저를 추가하시겠습니까? (0) | 2023.02.13 |
Woocommerce에서 프로그래밍 방식으로 새 제품 특성 생성 (0) | 2023.02.13 |