Good morning,
This is probably an easy question for someone here to answer.. I'm sure I've just been staring at this for too long and lost focus.
Here's my issue..
I'm using Spring STS 3.1.0 to develop a Spring MVC REST API.
Here's my web.xml.. it's pretty generic.. I don't think I've changed a thing that wasn't auto-generated:
Code:<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" 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_2_5.xsd"> <!-- 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/root-context.xml</param-value> </context-param> <!-- Creates the Spring Container shared by all Servlets and Filters --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Processes application requests --> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
Here's my root-context.xml, pretty basic, nothing out of the ordinary here:
Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- Root Context: defines shared resources visible to all other web components --> <bean id="dbDataSource" class="org.apache.commons.dbcp.BasicDataSource"> ... </bean> </beans>
The only other config file is my servlet's spring configuration.. In there, there's nothing that sets the base path for the application, only URI configs inside the @Controller's themselves, right?
Code:<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:oxm="http://www.springframework.org/schema/oxm" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd"> <resources mapping="/resources/**" location="/resources/" /> <beans:bean id="uregJdbcTemplate" class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate"> <beans:constructor-arg ref="dbDataSource" /> </beans:bean> <beans:bean class="com.mycompany.dao.UserDaoImpl" id="userDao"> <beans:property name="dataSource" ref="dbDataSource" /> </beans:bean> <beans:bean class="com.mycompany.service.UserServiceImpl" id="userService" /> <context:component-scan base-package="com.mycompany.api, com.mycompany.dao, com.mycompany.dom" /> <interceptors> <beans:bean class="com.mycompany.api.interceptors.ApiRequestInterceptor" /> </interceptors> <annotation-driven /> </beans:beans>
The problem I'm having is, everything works fine if I access my servlet as (note the /api in the url):
http://localhost:8080/api/myRequestMapping
I would really like to change and/or eliminate the /api in the request path
Where is this being defined (the servlet-mapping is just / for this servlet, and the servlet name is appServlet, not api)?
Is there a deployment target configuration for this project in my Spring STS IDE Tomcat settings that I'm not seeing that's setting the context to /api during deployment?
I'm baffled to be honest. lol.
Besides this, everything's working great.
Thanks in advance for your input.


Reply With Quote