我正在用jersey开发spring boot中的应用程序。我是Spring靴的新手。当我尝试在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.apache.catalina.core.StandardContext.startInternal:无法启动嵌入式容器;嵌套异常StandardContext.java:5156:无效的*/在servlet映射在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)在java.lang.IllegalArgumentException(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(SpringBootServletInitializer.java:133)在org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:124)在org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringServletContainerInitializer.java:175)在org.springframework.context.ApplicationContextException(java.lang.IllegalArgumentException)在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133)…10更多由:org.springframework.context.support.AbstractApplicationContext.refresh:无效的*/在servlet映射在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)在org. springframe. boot. conttext. EmbeddedWebApplication ationContext. java: 195)在org. springframe. boot. text. embeddedWebApplication ationContext. java: 222)在org. springframe. boot. text. embeddedWebApplication. access 0美元(EmbeddedWebApplication ationContext. java:
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"
<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>
砰.xml
http://maven.apache.org/maven-v4_0_0.xsd"
<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配置公共类Jersey初始化扩展了ResourceConfig{
}
异常(或者更确切地说是它的原因)准确地告诉你哪里出了问题:
servlet映射中的*/无效
在 Java 代码中,您尝试实例化 Servlet 注册Bean,
如下所示:
ServletRegistrationBean register =
new ServletRegistrationBean(new ServletContainer(),"*/");
因为异常情况表明 */
不是有效的 servlet 映射。您可能想要 /*
来代替。
根据Java Servlet规范:
在Web应用程序部署描述符中,以下语法用于定义映射:
我刚开始使用Spring Boot,在运行我的应用程序时出现了错误。我正在学习教程,我相信我有正确的父母和依赖与POM,请帮助我 主类: POM:
我正在学习《行动中的Spring》第四版第5章,但是我被第一个例子困住了。 以下是我的Eclipse Luna项目结构: 如果我将此项目作为Spring Boot应用程序运行,则会引发异常: 我怎样才能解决这个问题? 所有文件的内容: 随地吐痰。爪哇: SpittrWebAppInitializer.java: 网络配置。爪哇: RootConfig。爪哇: HomeController.java
我是Spring的新手,所以我从Spring intializr下载了jar for maven-web java 1.8 demo。我将其提取并导入STS以运行main()文件,我得到了以下异常。有人能告诉我有什么解决方案吗? 我从Web尝试但不起作用的解决方案:-尝试将Hibernate验证器依赖项添加到pom-尝试将spring-boot-starter-tomcat依赖项添加到pom 堆栈
说明:无法启动web服务器;嵌套的异常是org。springframework。靴子网状物服务器WebServerException:无法启动嵌入式Tomcat 启动Tomcat上下文时出错。例外情况: 组织。springframework。豆。工厂BeanCreationException。消息:创建在类路径资源[org/springframework/boot/actuate/autoconf
我有一个Spring Boot应用程序演示,遵循以下指南https://spring.io/guides/gs/rest-service/ PS:因为启动类不在我的bean的同一个包中,所以我显式地将@componentscan添加到我的启动类中。