我正在創建基於REST
的Web應用程序,其中AngularJS
作爲前端和基於REST
的後端(使用Spring 4
)。我下面這裏找到基於代碼的配置方法:WebApplicationInitializerWebApplicationInitializer container.addFilter()返回null
當我在服務器上運行的項目,我在該行獲得一個空值:
FilterRegistration.Dynamic filter = container.addFilter("prerender", seoFilter);
我缺少什麼?我從頭開始使用註釋創建web應用程序有點新。
這裏是有問題的類:
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");
}
此行是給我空
com.github.greengerong.PreRenderSEOFilter seoFilter = new com.github.greengerong.PreRenderSEOFilter();
我想這一點,但同樣的結果
FilterRegistration.Dynamic filter1 = container.addFilter("prerender", com.github.greengerong.PreRenderSEOFilter.class);
可以共享異常堆棧跟蹤 – Mudassar
是否已經閱讀了[Javadoc中(http://docs.oracle.com/ javae/7/api/javax/servlet/ServletContext.html#addFilter-java.lang.String-javax.servlet.Filter-)並排除了所有'addFilter()'方法返回null的情況? –