0

I am currently working on a project which is separated into frontend (html5, jquery, css) and backend (Spring4 mvc with java config -no web.xml-, exposing rest for the view to consume it), each of which has its own pom that depends on the same parent pom.

Project's tree structure

When I compile the main project, 2 wars are generated (front and backend), which I later deploy in tomcat 7.

Backend is working fine (i've already tested it with psotman) and frontend works fine also if I open the html from outside tomcat (when I open index.html from a folder on my computer). However when I deploy the frontend war together with te backend war in tomcat and enter "localhost:8080/myAppsName/", http eror 404 is thrown. I understand that the html can't be found in order to render the index page.

frontend tree structure

Backend 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;
    }

}

Backend 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[] { "/" };
    }

}

I DO have a web.xml in project frontend which is actually empty:

<?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>

My question is: - How should I set index.html to be the default home page of my app when entering localhost:8080/myAppsName?

1 Answer 1

0

Just update your frontend modules web.xml file with welcome-file-list.

<?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>
Sign up to request clarification or add additional context in comments.

1 Comment

THANK YOU! I had also to move index.html from "/frontend/index.html" to "/index.html"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.