请帮助我,因为我无法在springboot应用程序中找出问题所在。我正在使用以下pom.xml
<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 9时,出现以下错误:
java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:171)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
com.b.AuthenticationFilter.doFilter(AuthenticationFilter.java:665)
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
当我使用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
如果任何人都知道如何解决,请提供帮助。
答案 0 :(得分:2)
您的POM包含一些依赖项,这些依赖项之间存在版本冲突。
10.0.3.0/24 dev eth2 proto kernel scope link src 10.0.3.5
192.168.110.0/24 dev eth1 proto kernel scope link src 192.168.110.232
cidr_networks:
container: 192.168.110.0/24
tunnel: 192.168.32.0/24
storage: 10.0.3.0/24
used_ips:
- "192.168.110.1,192.168.110.2"
- "192.168.110.111"
- "192.168.110.115"
- "192.168.110.117,192.168.110.118"
- "192.168.110.131,192.168.110.140"
- "192.168.110.201,192.168.110.207"
- "192.168.32.1,192.168.32.2"
- "192.168.32.201,192.168.32.207"
- "10.0.3.1"
- "10.0.3.11,10.0.3.14"
- "10.0.3.21,10.0.3.24"
- "10.0.3.31,10.0.3.42"
- "10.0.3.201,10.0.3.207"
global_overrides:
# The internal and external VIP should be different IPs, however they
# do not need to be on separate networks.
external_lb_vip_address: 192.168.100.168
internal_lb_vip_address: 192.168.110.201
management_bridge: "br-mgmt"
provider_networks:
- network:
container_bridge: "br-mgmt"
container_type: "veth"
container_interface: "eth1"
ip_from_q: "container"
type: "raw"
group_binds:
- all_containers
- hosts
is_container_address: true
- network:
container_bridge: "br-vxlan"
container_type: "veth"
container_interface: "eth10"
ip_from_q: "tunnel"
type: "vxlan"
range: "1:1000"
net_name: "vxlan"
group_binds:
- neutron_linuxbridge_agent
- network:
container_bridge: "br-ext1"
container_type: "veth"
container_interface: "eth12"
host_bind_override: "eth12"
type: "flat"
net_name: "ext_net"
group_binds:
- neutron_linuxbridge_agent
- network:
container_bridge: "br-storage"
container_type: "veth"
container_interface: "eth2"
ip_from_q: "storage"
type: "raw"
group_binds:
- glance_api
- cinder_api
- cinder_volume
- nova_compute
- swift-proxy
###
### Infrastructure
###
# galera, memcache, rabbitmq, utility
shared-infra_hosts:
infra1:
ip: 192.168.110.201
# repository (apt cache, python packages, etc)
repo-infra_hosts:
infra1:
ip: 192.168.110.201
# load balancer
haproxy_hosts:
infra1:
ip: 192.168.110.201
###
### OpenStack
###
os-infra_hosts:
infra1:
ip: 192.168.110.201
identity_hosts:
infra1:
ip: 192.168.110.201
network_hosts:
infra1:
ip: 192.168.110.201
compute_hosts:
compute1:
ip: 192.168.110.204
compute2:
ip: 192.168.110.205
compute3:
ip: 192.168.110.206
compute4:
ip: 192.168.110.207
storage-infra_hosts:
infra1:
ip: 192.168.110.201
storage_hosts:
lvm-storage1:
ip: 192.168.110.202
container_vars:
cinder_backends:
lvm:
volume_backend_name: LVM_iSCSI
volume_driver: cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group: cinder_volumes
iscsi_ip_address: "{{ cinder_storage_address }}"
limit_container_types: cinder_volume
的{{1}}版本已使用Tomcat <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
构建
Tomcat 9及更高版本位于servlet 4.x上
从2.3.3.RELEASE
中删除以下依赖项,可以缓解依赖项问题。
spring-boot-starter-web
和
9.0.37
因为这些是可传递的依赖项,而这些依赖项已经由项目中的依赖项提供。
您可以使用pom.xml
检查您的依赖关系树并观察任何潜在的依赖冲突。
答案 1 :(得分:1)
我有一个类似的问题,原因是jsp-api不适合相应的servlet-api版本。正如SvenDöring已经提到的那样,Spring Boot 2.1.x使用Tomcat 9,后者使用/提供了Servlet API v4。为此,您需要jsp-api 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>
答案 2 :(得分:1)
缺少的方法HttpServletRequest.getHttpServletMapping()
已添加到版本4的Servlet API中,因此问题是由您对Servlet 3.1 API的依赖引起的:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
spring-boot-starter-web
已包含对Servlet API的依赖,因此无需声明。从您的pom.xml
中删除上述内容应该可以解决您的问题。