当我将生成的 .war 文件部署到独立的 Tomcat 服务器时出现错误 404,但如果我在 IDE(IntelliJ)中使用 Tomcat 服务器部署战争,它工作正常。
这是初始化器
public void onStartup(ServletContext servletContext)
throws ServletException {
AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
mvcContext.register(AppConfig.class);
servletContext.addListener(new ContextLoaderListener(mvcContext));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
"dispatcher", new DispatcherServlet(mvcContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
这是应用程序配置
**Tiles Configuration**
@Bean
public TilesConfigurer getTilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setDefinitions(
"/WEB-INF/defs/tiles.xml");
return tilesConfigurer;
}
@Bean
public UrlBasedViewResolver getUrlBasedResolver() {
UrlBasedViewResolver urlBasedViewResolver = new UrlBasedViewResolver();
urlBasedViewResolver.setViewClass(new TilesView().getClass());
return urlBasedViewResolver;
}
/** End of Tiles Configuration */
**View Resolver:**
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/pages/**");
resolver.setSuffix(".jsp");
return resolver;
**Tiles.xml**
<definition name="hello-tiles" extends="commons">
<put-attribute name="header" value="/WEB-INF/template/header2.jsp" />
<put-attribute name="title" value="Hello Page" />
<put-attribute name="body" value="/WEB-INF/pages/hello.jsp" />
</definition>