无法启动嵌入式容器;嵌套异常是 java.lang.IllegalArgumentException: Invalid <url-pattern> */ in servlet mappin
Posted
技术标签:
【中文标题】无法启动嵌入式容器;嵌套异常是 java.lang.IllegalArgumentException: Invalid <url-pattern> */ in servlet mapping Spring boot【英文标题】:Unable to start embedded container; nested exception is java.lang.IllegalArgumentException: Invalid <url-pattern> */ in servlet mapping Spring boot 【发布时间】:2015-12-26 20:20:50 【问题描述】:我正在用球衣在 Spring Boot 中开发一个应用程序。我是Spring boot的新手。当我尝试在tomcat7.0中部署war时,出现以下错误
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/leasing-management-spring]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1768)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
原因:org.springframework.context.ApplicationContextException:无法启动嵌入式容器;嵌套异常是 java.lang.IllegalArgumentException: Invalid */ in servlet mapping 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:321) 在 org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:133) 在 org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:124) 在 org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:81) 在 org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) 在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 10 更多 引起:java.lang.IllegalArgumentException: Invalid */ in servlet mapping 在 org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3075) 在 org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3050) 在 org.apache.catalina.core.ApplicationServletRegistration.addMapping(ApplicationServletRegistration.java:192) 在 org.springframework.boot.context.embedded.ServletRegistrationBean.configure(ServletRegistrationBean.java:211) 在 org.springframework.boot.context.embedded.ServletRegistrationBean.onStartup(ServletRegistrationBean.java:195) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:222) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access$000(EmbeddedWebApplicationContext.java:84) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext$1.onStartup(EmbeddedWebApplicationContext.java:206) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ... 20 更多 web.xml
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> 宁静的 Web 应用程序 org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener
<filter>
<filter-name>metricFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>metricFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
pom.xml
http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 邀请函 springBootCore 战争 1.0-快照 租赁 Maven Webapp http://maven.apache.org
<properties>
<project.java.version>1.8</project.java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.3.0.v20150612</jetty.version>
<jersey.version>1.19</jersey.version>
<spring-boot.version>1.2.6.RELEASE</spring-boot.version>
<slf4j.version>1.6.6</slf4j.version>
<logback.version>1.0.9</logback.version>
<hibernate.version>4.3.6.Final</hibernate.version>
<spring.version>3.2.3.RELEASE</spring.version>
<atomikos.version>3.8.0</atomikos.version>
<sql.driver.version>4.0</sql.driver.version>
</properties>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>$jersey.version</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-guice</artifactId>
<version>$jersey.version</version>
</dependency>
<!-- <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId>
<version>$jersey.version</version> </dependency> -->
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-xml-provider</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<version>$spring-boot.version</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>$spring-boot.version</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>$spring-boot.version</version>
<scope>test</scope>
</dependency>
<!-- Spring boot Tomcat Dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>$spring-boot.version</version>
<scope>provided</scope>
</dependency>
<repositories>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<build>
<finalName>leasing-management-spring</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>$project.java.version</source>
<target>$project.java.version</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>$jetty.version</version>
<configuration>
<reload>automatic</reload>
<scanIntervalSeconds>20</scanIntervalSeconds>
<stopKey>todostop</stopKey>
<stopPort>9999</stopPort>
</configuration>
</plugin>
</plugins>
</build>
</project>
Spring 引导代码
@SpringBootApplication
public class Application extends SpringBootServletInitializer
@Override
protected SpringApplicationBuilder configure
(SpringApplicationBuilder application)
return application.sources(Application.class);
public static void main(String[] args) throws Exception
SpringApplication.run(Application.class, args);
@Bean
public ServletRegistrationBean jerseyServlet()
ServletRegistrationBean register =
new ServletRegistrationBean(new ServletContainer(),"*/");
register.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyInitialization.class.getName());
return register;
Jersey Configuration
public class JerseyInitialization extends ResourceConfig
public JerseyInitialization()
this.packages("in.vit.leasing.core.api");
【问题讨论】:
【参考方案1】:异常(或者更确切地说是它的原因)会告诉你究竟出了什么问题:
在 servlet 映射中 */ 无效
在您的 Java 代码中,您尝试像这样实例化 ServletRegistrationBean
:
ServletRegistrationBean register =
new ServletRegistrationBean(new ServletContainer(),"*/");
正如异常所说,*/
不是有效的 servlet 映射。你
可能想要/*
。
来自Java Servlet Specification:
在 Web 应用程序部署描述符中,使用以下语法来定义映射:
以“/”字符开头并以“/*”结尾的字符串 后缀用于路径映射。 以‘ * 开头的字符串。 ' 前缀用作扩展映射。 空字符串 ("") 是一种特殊的 UR L 模式,它精确映射到应用程序的上下文根,即 http://host:port// 形式的请求。在这种情况下,路径信息是“/”,servlet 路径和上下文路径是空字符串(“”)。 仅包含“/”字符的字符串表示应用程序的“默认”servlet。在这种情况下,servlet 路径是请求 URI 减去上下文路径,并且路径信息为空。 所有其他字符串仅用于完全匹配。
【讨论】:
以上是关于无法启动嵌入式容器;嵌套异常是 java.lang.IllegalArgumentException: Invalid <url-pattern> */ in servlet mappin的主要内容,如果未能解决你的问题,请参考以下文章
无法启动 bean 'stompBrokerRelayMessageHandler';嵌套异常是 java.lang.NoClassDefFoundError: io/netty/util/concu
HTTP 状态 500 - 请求处理失败。嵌套异常是 java.lang.NullPointerException [重复]
线程“主”org.springframework.context.ApplicationContextException 中的异常:无法启动嵌入式容器;
HTTP状态500-请求处理失败;嵌套的异常是java.lang.NullPointerException?
构造函数抛出异常嵌套异常是 java.lang.nullpointerexception
java.rmi.UnmarshalException:解组参数错误;嵌套异常是:java.lang.ClassNotFoundException: ServicesTableau