i creating rest-based web application angularjs front end , rest-based backend (with spring 4). following code-based configuration approach found here: webapplicationinitializer
when run project on server, null value in line:
filterregistration.dynamic filter = container.addfilter("prerender", seofilter); what missing? bit new creating web-apps scratch using annotations.
here class in question:
public class mywebappinitializer implements webapplicationinitializer { @override public void onstartup(servletcontext container) throws servletexception { xmlwebapplicationcontext appcontext = new xmlwebapplicationcontext(); appcontext.setconfiglocation("classpath:mycontext.xml"); servletregistration.dynamic dispatcher = container.addservlet("dispatcher", new dispatcherservlet(appcontext)); dispatcher.setloadonstartup(1); dispatcher.addmapping("/api/*"); com.github.greengerong.prerenderseofilter seofilter = new com.github.greengerong.prerenderseofilter(); filterregistration.dynamic filter = container.addfilter("prerender", seofilter); filter.setinitparameter("prerendertoken", "123456789123456789"); filter.addmappingforurlpatterns(null , true, "/*"); servletregistration.dynamic initsysconfiguration = container.addservlet("initsysconfiguration", new initsystemconfigurations()); initsysconfiguration.setloadonstartup(1); initsysconfiguration.addmapping("/initsystemconfigurations"); } this line give me null
com.github.greengerong.prerenderseofilter seofilter = new com.github.greengerong.prerenderseofilter(); i tried this,but same result
filterregistration.dynamic filter1 = container.addfilter("prerender", com.github.greengerong.prerenderseofilter.class);
when method addfilter returns null means there a filter registered name.
returns:
filterregistrationobject may used further configure given filter, ornullifservletcontextcontains completefilterregistrationfilter givenfilternameor if same filter instance has been registered orservletcontextin same container
make sure don't have web.ml registers filter.
another tip instead of implementing webapplicationinitializer extend abstractdispatcherservletinitializer , implement needed methods.
public class mywebappinitializer extends abstractdispatcherservletinitializer { @override public void onstartup(servletcontext container) throws servletexception { super.onstartup(container); com.github.greengerong.prerenderseofilter seofilter = new com.github.greengerong.prerenderseofilter(); filterregistration.dynamic filter = container.addfilter("prerender", seofilter); filter.setinitparameter("prerendertoken", "123456789123456789"); filter.addmappingforurlpatterns(null , true, "/*"); servletregistration.dynamic initsysconfiguration = container.addservlet("initsysconfiguration", new initsystemconfigurations()); initsysconfiguration.setloadonstartup(1); initsysconfiguration.addmapping("/initsystemconfigurations"); } protected webapplicationcontext createservletapplicationcontext() { xmlwebapplicationcontext appcontext = new xmlwebapplicationcontext(); appcontext.setconfiglocation("classpath:mycontext.xml"); return appcontext; } protected string[] getservletmappings() { return new string[] {"/api/*"}; } }
Comments
Post a Comment