tomcat - Application context being loaded twice - Spring Boot -


i have simple setup. maven project 3 modules : core/webapp/model. i'm using spring boot gear application. in webapp, have simple class webappconfig follows:

@configuration @enableautoconfiguration @componentscan(excludefilters = @componentscan.filter(configuration.class)) public class webappconfig {      public static void main(string[] args) {         springapplication app = new springapplication(webappconfig.class);         app.setadditionalprofiles("dev");         app.run(args);     } } 

and few classes in core/model module. container-application point :

public class abcdxml extends springbootservletinitializer {      @override     protected springapplicationbuilder configure(springapplicationbuilder application) {         return application.sources(webappconfig.class);     }  } 

and no web.xml! model's pom has following spring boot related dependency :

<dependency>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-data-jpa</artifactid> </dependency> 

core's pom.xml :

<dependency>       <groupid>org.springframework.boot</groupid>       <artifactid>spring-boot-starter-test</artifactid>       <scope>test</scope> </dependency> <dependency>     <groupid>org.springframework.boot</groupid>     <artifactid>spring-boot-starter-web</artifactid> </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-batch</artifactid> </dependency> 

now running webappconfig via run -> java application works need deploy project war on tomcat7. webapp's packaging war. there no tomcat provided jar's in lib except tomcat-jdbc , tomcat-tuli jar(shouldn't issue?).

when deploy abcd.war, applicationcontext getting loaded twice , result in following error stracktrace :

2014-06-27 11:06:08.445  info 23467 --- [ost-startstop-1] o.a.c.c.c.[.[localhost].[/abcd]        : initializing spring embedded webapplicationcontext 2014-06-27 11:06:08.446  info 23467 --- [ost-startstop-1] o.s.web.context.contextloader            : root webapplicationcontext: initialization completed in 19046 ms 2014-06-27 11:06:21.308  info 23467 --- [ost-startstop-1] o.s.b.c.e.servletregistrationbean        : mapping servlet: 'dispatcherservlet' [/] 2014-06-27 11:06:21.313  info 23467 --- [ost-startstop-1] o.s.b.c.embedded.filterregistrationbean  : mapping filter: 'errorpagefilter' to: [/*] 2014-06-27 11:06:21.314  info 23467 --- [ost-startstop-1] o.s.b.c.embedded.filterregistrationbean  : mapping filter: 'hiddenhttpmethodfilter' to: [/*] 2014-06-27 11:06:26.073  info 23467 --- [ost-startstop-1] j.localcontainerentitymanagerfactorybean : building jpa container entitymanagerfactory persistence unit 'default' 2014-06-27 11:06:26.127  info 23467 --- [ost-startstop-1] o.hibernate.jpa.internal.util.loghelper  : hhh000204: processing persistenceunitinfo [     name: default     ...] 2014-06-27 11:06:26.511  info 23467 --- [ost-startstop-1] org.hibernate.version                    : hhh000412: hibernate core {4.3.1.final} 2014-06-27 11:06:26.521  info 23467 --- [ost-startstop-1] org.hibernate.cfg.environment            : hhh000206: hibernate.properties not found 2014-06-27 11:06:26.527  info 23467 --- [ost-startstop-1] org.hibernate.cfg.environment            : hhh000021: bytecode provider name : javassist //some info messages spring boot 2014-06-27 11:07:31.664  info 23467 --- [ost-startstop-1] o.s.w.s.handler.simpleurlhandlermapping  : mapped url path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler] 2014-06-27 11:07:33.095  info 23467 --- [ost-startstop-1] o.s.w.s.handler.simpleurlhandlermapping  : mapped url path [/**] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler] 2014-06-27 11:07:33.096  info 23467 --- [ost-startstop-1] o.s.w.s.handler.simpleurlhandlermapping  : mapped url path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler] 2014-06-27 11:07:36.080  info 23467 --- [ost-startstop-1] o.s.j.e.a.annotationmbeanexporter        : registering beans jmx exposure on startup 2014-06-27 11:08:49.583  info 23467 --- [ost-startstop-1] o.s.boot.springapplication               : started application in 183.152 seconds (jvm running 210.258) 2014-06-27 11:12:29.229 error 23467 --- [ost-startstop-1] o.a.c.c.c.[.[localhost].[/abcd]        : exception sending context initialized event listener instance of class org.springframework.web.context.contextloaderlistener  java.lang.illegalstateexception: cannot initialize context because there root application context present - check whether have multiple contextloader* definitions in web.xml!     @ org.springframework.web.context.contextloader.initwebapplicationcontext(contextloader.java:277)     @ org.springframework.web.context.contextloaderlistener.contextinitialized(contextloaderlistener.java:106)     @ org.apache.catalina.core.standardcontext.listenerstart(standardcontext.java:4937)     @ org.apache.catalina.core.standardcontext.startinternal(standardcontext.java:5434)     @ org.apache.catalina.util.lifecyclebase.start(lifecyclebase.java:150)     @ org.apache.catalina.core.containerbase.addchildinternal(containerbase.java:901)     @ org.apache.catalina.core.containerbase.addchild(containerbase.java:877)     @ org.apache.catalina.core.standardhost.addchild(standardhost.java:633)     @ org.apache.catalina.startup.hostconfig.deploywar(hostconfig.java:976)     @ org.apache.catalina.startup.hostconfig$deploywar.run(hostconfig.java:1653)     @ java.util.concurrent.executors$runnableadapter.call(executors.java:471)     @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:334)     @ java.util.concurrent.futuretask.run(futuretask.java:166)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1110)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:603)     @ java.lang.thread.run(thread.java:722) 

there no web.xml mentioned earlier.

few interesting things can't figure out why :

  1. after exploding war, tomcat somehow create root folder default web.xml[must spring boot misconfiguration. how can correct it? pointers please?]
  2. even if return same 'application' springapplicationbuilder in abcdxml.java, facing same issue of applicationcontext being loaded twice.

thanks help!

edit 1:

content of web.xml generated in root folder :

<?xml version="1.0" encoding="iso-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version="2.5"> </web-app> 

if app includes jersey-spring3 , don't take steps disable, try create applicationcontext (helpful, not). there way switch off (in webapplicationinitializer):

servletcontext.setinitparameter("contextconfiglocation", "<none>"); 

or use this: https://github.com/dsyer/spring-boot-jersey (include dependency).


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -