Como definir o caminho de contexto raiz do Spring
Eu sou um novato no Spring e estou montando um aplicativo da web no Spring (não no Spring-boot - quanta diferença isso faz?). A implantação está em um servidor Tomcat 7.
O aplicativo está instalado e funcionando. Meu problema é que só é acessível através do URL padrão:
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/index.html
O seguinte não funciona:http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/
apesar de meu web.xml listar index.html como a página de boas-vindas.
Um sintoma adicional do problema é que todos os tipos de links no aplicativo precisam ser especificados como relativos, e não com um '/' anexado.
Mas mesmo esses URLs não são o que eu realmente quero.
Eu prefiro especificar
http://mycompany.com:8081/cwing
e solicite o index.html.
Seguindo a liderança deAdicionar caminho de contexto ao aplicativo Spring Boot
Criei um arquivo application.xml em src / main / resources com o seguinte conteúdo:
server.contextPath=/cwing
server.port=8081
Isso não funciona.http://mycompany.com:8081/cwing abre uma página em branco, com um erro 404 no servidor, assim comohttp://mycompany.com:8081/cwing/index.html.
Eu devo estar esquecendo alguma coisa. O que mais é necessário para que isso funcione como eu quero?
UPDATE: conforme solicitado, aqui está o web.xml (detalhes irrelevantes removidos).
<?xml version="1.0"?>
<web-app 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"
version="3.0">
<display-name>cwing</display-name>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>d</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>d</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Disables Servlet Container welcome file handling. Needed for compatibility
with Servlet 3.0 and Tomcat 7.0 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
...
</web-app>