首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring 4 java配置,前后端分离wars,设置localhost主页:port/myAppsName/

Spring 4 java配置,前后端分离wars,设置localhost主页:port/myAppsName/
EN

Stack Overflow用户
提问于 2017-02-10 00:38:44
回答 1查看 74关注 0票数 0

我目前正在做一个项目,分为前端(html5,jquery,css)和后端(使用java config -no web.xml的Spring4 mvc -,暴露rest以供视图使用),每个项目都有自己的pom,依赖于相同的父pom。

Project's tree structure

当我编译主项目时,生成了两个wars (前端和后端),稍后我将它们部署到tomcat7中。

后端工作得很好(我已经用psotman测试过了),前端也工作得很好,如果我从tomcat外部打开html (当我从电脑上的文件夹打开index.html时)。但是,当我在tomcat中部署前端war和后端war并输入"localhost:8080/myAppsName/“时,会抛出http错误404。我知道无法找到用于呈现索引页面的html。

frontend tree structure

后端AppConfig.java:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
    @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,它实际上是空的:

代码语言:javascript
复制
<?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设置为我的应用程序的默认主页?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-10 08:04:10

只需使用欢迎文件列表更新您的前端模块web.xml文件即可。

代码语言:javascript
复制
<?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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42142141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档