I am trying to deploy a Spring MVC application at root in Tomcat8. At the moment, the only way I can access my app is at my_domain_name.com/my_webapp, where my_webapp is the name of my war file; whereas I would like to access it at just my_domain_name.com.
I know there are other similar questions on this topic but I've tried everything and only renaming my war file to ROOT.war worked, but this is not ideal for me as I want to run multiple apps from the same server.
My server.xml includes:
<Context path="" docBase="my_webapp" debug="0" reloadable="true">
</Context>
<Host name="my_domain_name.com" appBase="my_webapp"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="my_webapp_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
I have a ROOT.xml file in the conf directory:
<Context
docBase="my_webapp"
path=""
reloadable="true"/>
My context.xml under META-INF in my_webapp:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/"/>
Configuration file AppInitializer.java in my_webapp:
public class AppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new
AnnotationConfigWebApplicationContext();
rootContext.register(AppConfig.class);
container.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext dispatcherContext =
new AnnotationConfigWebApplicationContext();
ServletRegistration.Dynamic dispatcher =
container.addServlet("dispatcher", new
DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
Configuration file DefaultView in my_webapp:
public class DefaultView extends WebMvcConfigurerAdapter{
@Override
public void addViewControllers( ViewControllerRegistry registry ) {
registry.addViewController( "/" ).setViewName(
"forward:/home.html" );
registry.setOrder( Ordered.HIGHEST_PRECEDENCE );
super.addViewControllers( registry );
}
}
I think that's all the relevant files, but if you think it may be something else let me know. I don't know if there maybe something wrong with my Spring MVC configuration and/or Tomcat configuration. Many thanks in advance.
Edit: this question is not a duplicate - I am not asking how to deploy multiple webapps from different contexts as such. I would like my webapp to be deployed properly at root, so I should be just entering my www.myapp.com instead of www.myapp.com/myapp. I want to do this without naming my war file to ROOT.war - I have tried adding tags but this does not seem to work. I have also created a ROOT.xml and this is also not working. Quite clearly not a duplication of the question.