我目前正在做一个项目,分为前端(html5,jquery,css)和后端(使用java config -no web.xml的Spring4 mvc -,暴露rest以供视图使用),每个项目都有自己的pom,依赖于相同的父pom。
当我编译主项目时,生成了两个wars (前端和后端),稍后我将它们部署到tomcat7中。
后端工作得很好(我已经用psotman测试过了),前端也工作得很好,如果我从tomcat外部打开html (当我从电脑上的文件夹打开index.html时)。但是,当我在tomcat中部署前端war和后端war并输入"localhost:8080/myAppsName/“时,会抛出http错误404。我知道无法找到用于呈现索引页面的html。
后端AppConfig.java:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "org.fedelaper.spring")
public class AppConfig {
@Bean
public ViewResolver internalResourceViewResolver() {
InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
internalResourceViewResolver.setPrefix("/frontend/");
internalResourceViewResolver.setSuffix(".html");
return internalResourceViewResolver;
}
}后端AppInitializer.java:
@SuppressWarnings("unchecked")
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@SuppressWarnings("rawtypes")
@Override
protected Class[] getRootConfigClasses() {
return new Class[] { AppConfig.class };
}
@SuppressWarnings("rawtypes")
@Override
protected Class[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}我在项目前端有一个web.xml,它实际上是空的:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
</web-app>我的问题是:-当我进入localhost:8080/myAppsName时,我应该如何将index.html设置为我的应用程序的默认主页?
发布于 2017-02-10 08:04:10
只需使用欢迎文件列表更新您的前端模块web.xml文件即可。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>https://stackoverflow.com/questions/42142141
复制相似问题