我正在使用平针织物开发春季靴子的应用程序。我是Spring的新手。当我尝试在tomcat7.0中部署战争时,我遇到以下错误
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:servlet映射中的* /无效 at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) at 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) at 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:servlet映射中的* /无效 在org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3075) at 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) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.selfInitialize(EmbeddedWebApplicationContext.java:222) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.access $ 000(EmbeddedWebApplicationContext.java:84) 在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext $ 1.onStartup(EmbeddedWebApplicationContext.java:206) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) at 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“&GT; 4.0.0 in.vit.leasing springBootCore 战争 1.0-SNAPSHOT 租赁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 Boot Code
@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");
}
}
答案 0 :(得分:0)
例外(或更确切地说是其原因)告诉你到底出了什么问题:
servlet映射中的* /无效
在Java代码中,您尝试像这样实例化ServletRegistrationBean
:
ServletRegistrationBean register =
new ServletRegistrationBean(new ServletContainer(),"*/");
正如异常所说*/
不是有效的servlet映射。您
可能需要/*
代替。
在Web应用程序部署描述符中,以下语法用于定义映射:
- 以“/”字符开头并以“/ *”结尾的字符串 后缀用于路径映射。
- 以'*开头的字符串。 '前缀用作扩展名映射。
- 空字符串(&#34;&#34;)是一个特殊的UR L模式,它完全映射到应用程序的上下文根,即http://host:port/ /形式的请求。在这种情况下,路径信息是'/',servlet路径和上下文路径是空字符串(“”)。
- 仅包含'/'字符的字符串表示&#34;默认&#34;应用程序的servlet。在这种情况下,servlet路径是请求URI减去上下文路径,路径信息为null。
- 所有其他字符串仅用于完全匹配。