java - No WebApplicationContext found: no ContextLoaderListener registered?, but not every time that start the server -
i need solve problem... i'm working spring-mvc 4.1.6.release, spring-security 4.0.0.release
i'm having error just... "sometimes" when start server. that's real problem happens sometimes.
java.lang.illegalstateexception: no webapplicationcontext found: no contextloaderlistener registered? @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:252) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:222) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:100) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:953) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1041) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:603) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:310) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745)
then say, that's easy have add contextloaderlistener when do, this:
java.lang.illegalstateexception: cannot initialize context because there root application context present - check whether have multiple contextloader* definitions in web.xml!
but not always... guess there wrong in order context being initialized don't know how fix it...
these configuration classes:
webinitializer.java
public class webinitializer implements webapplicationinitializer { @override public void onstartup(servletcontext servletcontext) throws servletexception { annotationconfigwebapplicationcontext rootcontext = new annotationconfigwebapplicationcontext(); rootcontext.register(serverapplicationconfig.class); servletcontext.addlistener(new requestcontextlistener()); servletcontext.addlistener(new contextloaderlistener(rootcontext)); facesservlet facesservlet = new facesservlet(); servletregistration.dynamic facesservletdynamic = servletcontext.addservlet("facesservlet", facesservlet); facesservletdynamic.addmapping("*.jsf"); facesservletdynamic.setloadonstartup(1); servletcontext.addlistener(configurelistener.class); //oauth2filter servletcontext.addfilter("auth2clientcontextfilter", oauth2clientcontextfilter.class); } }
serverapplicationconfig.java
@enablewebmvc @import({ websecurityconfig.class, hibernateconfig.class }) @componentscan(basepackages = { "com.agrichem.server" }, scopedproxy = scopedproxymode.target_class) @configuration public class serverapplicationconfig { @bean public propertyplaceholderconfigurer getpropertyplaceholderconfigurer() { timezone.setdefault(timezone.gettimezone("etc/utc")); propertyplaceholderconfigurer ppc = new propertyplaceholderconfigurer(); classpathresource[] resources = new classpathresource[] { new classpathresource("jdbc.properties"), new classpathresource("oada-client.properties") }; ppc.setlocations(resources); return ppc; } @bean @qualifier("viewresolver") public viewresolver getviewresolver() { urlbasedviewresolver viewresolver = new urlbasedviewresolver(); viewresolver.setviewclass(jsfview.class); viewresolver.setprefix("/views/"); viewresolver.setsuffix(".xhtml"); return viewresolver; } }
websecurityinitializer.java
@configuration @order(1) public class websecurityinitializer extends abstractsecuritywebapplicationinitializer { }
websecurityconfig.java
@configuration @enablewebsecurity public class websecurityconfig extends websecurityconfigureradapter { @autowired @qualifier("customuserdetailsservice") private userdetailsservice customuserdetailsservice; @autowired public void configureglobal(authenticationmanagerbuilder auth) throws exception { auth.userdetailsservice(customuserdetailsservice); } @override protected void configure(httpsecurity http) throws exception { http.csrf().disable(); http.logout().logouturl("/logout.jsf").permitall() .logoutsuccessurl("/home/login.jsf"); http.authorizerequests() .antmatchers("*.css", "*.js", "**.gif", "*.jpg", "*.jpeg", "*.png", "*.css.jsf", "*.js.jsf", "**.gif.jsf", "*.jpg.jsf", "*.jpeg.jsf", "*.png.jsf") .permitall() .antmatchers("/**/*.css", "/**/*.js", "/**/*.gif", "/**/*.jpg", "/**/*.jpeg", "/**/*.png", "/**/*.css.jsf", "/**/*.js.jsf", "/**/*.gif.jsf", "/**/*.jpg.jsf", "/**/*.jpeg.jsf", "/**/*.png.jsf") .permitall() .antmatchers("/**/*.woff2", "/**/*.eot", "/**/*.woff", "/**/*.ttf", "/**/*.svg", "*.woff2", "*.eot", "*.woff", "*.ttf", "*.svg", "/**/*.woff2.jsf", "/**/*.eot.jsf", "/**/*.woff.jsf", "/**/*.ttf.jsf", "/**/*.svg.jsf", "*.woff2.jsf", "*.eot.jsf", "*.woff.jsf", "*.ttf.jsf", "*.svg.jsf") .permitall(); http.authorizerequests().antmatchers("/admin/**.jsf").hasrole("admin"); // http.authorizerequests().antmatchers("/farms/**.jsf").hasanyrole("head_officer"); http.authorizerequests().antmatchers("/home/logout.jsf").permitall() .antmatchers("/rest/**").permitall(); http.authorizerequests().anyrequest().authenticated().and().formlogin() .loginpage("/home/login.jsf").permitall() .failureurl("/home/login.jsf?error=denied").permitall() .defaultsuccessurl("/home/index.jsf", true); } }
thanks in advance.
Comments
Post a Comment