0

I am working on a simple Spring boot application. The exposes a single point to retrieve application version. The application runs fine when deployed on a Tomcat server and when run as a spring Boot application. My problem is when I add Swagger dependencies to the POM file. I get the error below

2016-05-29 17:36:58.985 ERROR 2292 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Exception sending context initialized event to listener instance of class org.apache.tomcat.websocket.server.WsContextListener

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
    at org.apache.tomcat.websocket.server.WsServerContainer.<init>(WsServerContainer.java:147) ~[tomcat-embed-websocket-8.0.28.jar:8.0.28]
    at org.apache.tomcat.websocket.server.WsSci.init(WsSci.java:131) ~[tomcat-embed-websocket-8.0.28.jar:8.0.28]
    at org.apache.tomcat.websocket.server.WsContextListener.contextInitialized(WsContextListener.java:39) ~[tomcat-embed-websocket-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5181) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]

2016-05-29 17:36:58.986 ERROR 2292 --- [ost-startStop-1] o.apache.catalina.core.StandardContext   : One or more listeners failed to start. Full details will be found in the appropriate container log file
2016-05-29 17:36:58.996 ERROR 2292 --- [ost-startStop-1] o.apache.catalina.core.StandardContext   : Context [] startup failed due to previous errors
2016-05-29 17:36:59.119  INFO 2292 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-05-29 17:36:59.119  INFO 2292 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2016-05-29 17:36:59.144  INFO 2292 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-05-29 17:36:59.146  WARN 2292 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
2016-05-29 17:36:59.148  INFO 2292 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
2016-05-29 17:36:59.150  INFO 2292 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with 
2016-05-29 17:36:59.151 ERROR 2292 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:347) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:295) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1112) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1101) [spring-boot-1.3.0.RELEASE.jar:1.3.0.RELEASE]
    at com.example.config.Application.main(Application.java:34) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:478) [spring-boot-maven-plugin-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 24 common frames omitted
Caused by: java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
    at org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler.setServletContext(DefaultServletHttpRequestHandler.java:106) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.enable(DefaultServletHandlerConfigurer.java:75) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.enable(DefaultServletHandlerConfigurer.java:64) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at com.example.config.SpringWebConfig.configureDefaultServletHandling(SpringWebConfig.java:30) ~[classes/:na]
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.configureDefaultServletHandling(WebMvcConfigurerComposite.java:140) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.configureDefaultServletHandling(DelegatingWebMvcConfiguration.java:92) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping(WebMvcConfigurationSupport.java:451) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$517c00d7.CGLIB$defaultServletHandlerMapping$31(<generated>) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$517c00d7$$FastClassBySpringCGLIB$$ab7ff2a3.invoke(<generated>) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerBySpringCGLIB$$517c00d7.defaultServletHandlerMapping(<generated>) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 25 common frames omitted

[WARNING] 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:478)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.

Below is my spring boot application configuration

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

I am not using XML to config the application

public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    private static final Logger LOG = LoggerFactory.getLogger(ApplicationInitializer.class);

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {

    }

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return null;
    }

    @Override
    protected String[] getServletMappings() {
        return null;
    }

My MVC web configuration is as below

@EnableWebMvc
@Configuration
@ComponentScan(basePackages = "com.example.controller")
public class SpringWebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");

    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    InternalResourceViewResolver internalResourceViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }
}

A simple controller that reads some properties and send it back as JSON respones

@RestController
public class AppInfoController {

    @Autowired
    private ApplicationProperties properties;

    @RequestMapping(value = "/about", method = RequestMethod.GET)
    public AppInfo retrieveDevices() {
        return new AppInfo().withVersion(properties.getVersion())
                .withName(properties.getName())
                .withDescription(properties.getDescription());
    }


}

I use maven for bulding the application. dependency as below

 <properties>
        <jackson.version>2.4.4</jackson.version>
        <javax.el.version>2.2.4</javax.el.version>
        <jcl.slf4j.version>1.7.13</jcl.slf4j.version>
        <junit.version>4.12</junit.version>
        <logback.version>1.1.3</logback.version>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <mockito.version>1.10.19</mockito.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <servlet.version>3.0.1</servlet.version>
        <spring-boot.version>1.3.0.RELEASE</spring-boot.version>
        <springfox.version>2.3.0</springfox.version>
    </properties>

                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.mockito</groupId>
                    <artifactId>mockito-core</artifactId>
                </exclusion>
            </exclusions>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>


        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>${javax.el.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${jcl.slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- This seems to be the prblem child -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${springfox.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${springfox.version}</version>
        </dependency>
    </dependencies>

Dependency tree

INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ service-registry ---
[INFO] nz.co.sky:service-registry:war:1.0.0-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.0.RELEASE:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.13:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.13:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.16:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:1.3.0.RELEASE:compile
[INFO] |  |  \- org.hibernate:hibernate-validator:jar:5.2.2.Final:compile
[INFO] |  |     +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |     \- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:4.2.3.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:4.2.3.RELEASE:compile
[INFO] |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.2.3.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.0.RELEASE:provided
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.28:provided
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.28:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.28:provided
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.28:provided
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.3.0.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.3.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.3.0.RELEASE:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.springframework:spring-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.2.3.RELEASE:test
[INFO] +- org.apache.tomcat.embed:tomcat-embed-jasper:jar:8.0.28:provided
[INFO] |  \- org.eclipse.jdt.core.compiler:ecj:jar:4.4.2:provided
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.3:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO] +- javax.el:javax.el-api:jar:2.2.4:compile
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] +- junit:junit:jar:4.12:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.13:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.13:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |  \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] \- io.springfox:springfox-swagger2:jar:2.3.0:compile
[INFO]    +- org.mapstruct:mapstruct:jar:1.0.0.Final:compile
[INFO]    +- io.swagger:swagger-annotations:jar:1.5.4:compile
[INFO]    +- io.swagger:swagger-models:jar:1.5.4:compile
[INFO]    +- io.springfox:springfox-spi:jar:2.3.0:compile
[INFO]    |  \- io.springfox:springfox-core:jar:2.3.0:compile
[INFO]    +- io.springfox:springfox-schema:jar:2.3.0:compile
[INFO]    +- io.springfox:springfox-swagger-common:jar:2.3.0:compile
[INFO]    +- io.springfox:springfox-spring-web:jar:2.3.0:compile
[INFO]    +- com.google.guava:guava:jar:18.0:compile
[INFO]    +- com.fasterxml:classmate:jar:1.2.0:compile
[INFO]    +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO]    +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO]    \- org.springframework.hateoas:spring-hateoas:jar:0.19.0.RELEASE:compile
Maro
  • 4,065
  • 7
  • 33
  • 34
  • You seem very hard to try not to use spring boot (with all the configuration), but alas. swagger appears to pull in a different javax. servlet version (or depend on a different one) breaking things. What is the `${servlet.version}` point to? – M. Deinum May 29 '16 at 09:31
  • Why do you think I am not trying to use springboot? Actually it runs fine in tomcat, the issue the is when I try to run it as spring boot application. I am using servlet version 3.0.1 I've add the version and the dependency tree to the question, I see no trace of a conflicting servlet-api version – Maro May 29 '16 at 11:54
  • I do that is what the trace is telling you, try using the 3.1 version. I was referring to the fact of not using spring boot is because you try to do configuration that Spring Boot already does. Your `ApplicationInitializer` isn't being used and the `SpringWebConfig` can be removed as it doesn't add anything that Spring Boot doesn't already provide. The same for your dependencies, Spring Boot already manages most of those (like mockito, jUnit, jackson, logging etc. But you want to configure them. Using the spring boot managed versions will also give you compatible versions. – M. Deinum May 29 '16 at 17:46
  • @M.Deinum Thank you. Upgrading servlet-api version fixed the issue. {{ApplicationInitializer}} and {{SpringWebConfig}} is not for SpringBoot configuration it's needed to run when deployed into a container. As for the dependencies.. I'll look at what is being pulled by Spring and eliminate them as necessary. Please post your answer so I can accept it. Thanks – Maro May 30 '16 at 06:46
  • No it isn't... Spring Boot work as well, that is why you are extending `SpringBootServletInitializer`... Would be pretty useless for a framework if you suddenly need to do it by yourself. You can even see it isn't being used as you aren't allowed to return `null` from `getServletConfig` will not create a `DispatcherServlet` nor `ContextLoaderListener` those are still done by boot. (Trust me on that :) ) – M. Deinum May 30 '16 at 06:52
  • @M.Deinum You are right!!! i don't need the `ApplicationInitializer ` feels good to git rid of it. But If I get rid of `SpringWebConfig` how can we configure the view resolver and add resource handlers? – Maro May 30 '16 at 07:13
  • Those are already configured by Spring Boot (the resource is one of the defaults of Spring Boot). To configure the `InternalResourceViewResolver` just add `spring.mvc.view.suffix=.jsp` to your `application.properties`. Everything else is auto configured by Spring Boot already. – M. Deinum May 30 '16 at 07:20
  • I've done as you suggested and I am getting `Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'` what am i missing? – Maro May 30 '16 at 07:42
  • Did you add the properties to the `application.properties`? Also shouldn't you also have a `suffix` for your view resolver? – M. Deinum May 30 '16 at 07:45
  • Sorry it was my bad I've originally just removed the view resolver and kept the class. once i got rid of it everything worked like a charm. Thank you so much for your help. You rock man – Maro May 30 '16 at 07:55
  • What is the swagger library you used? – Supun Wijerathne May 31 '16 at 03:40
  • springfox swagger implementation – Maro Jun 01 '16 at 08:27

1 Answers1

0

you can try add this line : spring.mvc.pathmatch.matching-strategy=ant-path-matcher
to application.properties or if you use application.yml use this :

spring:
    mvc:
    pathmatch:
    matching-strategy: ant_path_matcher

another solution is to change the spring version like this :

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.4.0</version>
            <relativePath/> <!-- lookup parent from repository -->
       </parent> 
Youssef
  • 1
  • 1