0
votes

I am developing an application in spring boot with jersey. I'm new to Spring boot.When i try to deploy the war in tomcat7.0,I'm getting the following errors

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)

Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.IllegalArgumentException: Invalid */ in servlet mapping at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:687) at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:133) at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:124) at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:81) at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 10 more Caused by: java.lang.IllegalArgumentException: Invalid */ in servlet mapping at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3075) at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3050) at org.apache.catalina.core.ApplicationServletRegistration.addMapping(ApplicationServletRegistration.java:192) at org.springframework.boot.context.embedded.ServletRegistrationBean.configure(ServletRegistrationBean.java:211) at 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) at 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 more web.xml

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> Restful Web Application 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 in.vit.leasing springBootCore war 1.0-SNAPSHOT Leasing 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"); }

}

1

1 Answers

0
votes

The exception (or rather its cause) tells you exactly what's wrong:

Invalid */ in servlet mapping

In your Java code you try to instantiate the ServletRegistrationBean like this:

ServletRegistrationBean register = 
new ServletRegistrationBean(new ServletContainer(),"*/");

As the exception says */ is not a valid servlet mapping. You probably want /* instead.

From the Java Servlet Specification:

In the Web application deployment descriptor, the following syntax is used to define mappings:

  • A string beginning with a ‘ / ’ character and ending with a ‘ /* ’ suffix is used for path mapping.
  • A string beginning with a ‘ *. ’ prefix is used as an extension mapping.
  • The empty string ("") is a special UR L pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port//. In this case the path info is ’ / ’ and the servlet path and context path is empty string (““).
  • A string containing only the ’/ ’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
  • All other strings are used for exact matches only.