views:

879

answers:

1

I am having a trouble mapping a specific URL request to one of the controllers in my project.

the URL is : http://HOSTNAME/api/v1/profiles.json the war which is deployed is: api.war

the error I get is the following:

[PageNotFound] No mapping found for HTTP request with URI [/api/v1/profiles.json] in DispatcherServlet with name 'action'

The configuration I have is the following: web.xml :

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/applicationContext-security.xml</param-value>
 </context-param>

 <!-- Cache Control filter -->
 <filter>
  <filter-name>cacheControlFilter</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 </filter>

 <!-- Cache Control filter mapping -->
 <filter-mapping>
  <filter-name>cacheControlFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <!-- Spring security filter -->
 <filter>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
 </filter>

 <!-- Spring security filter mapping -->
 <filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <!-- Spring listener -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

 <!-- Spring Controller -->
 <servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/v1/*</url-pattern>
 </servlet-mapping> 

The action-servlet.xml:

<mvc:annotation-driven/>    

<bean id="contentNegotiatingViewResolver"
  class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  <property name="favorPathExtension" value="true" />
  <property name="favorParameter" value="true" />
  <!--
   default media format parameter name is 'format'
  -->
  <property name="ignoreAcceptHeader" value="false" />
  <property name="order" value="1" />
  <property name="mediaTypes">
      <map>
        <entry key="html" value="text/html"/> 
        <entry key="json" value="application/json" />
        <entry key="xml"  value="application/xml" /> 
      </map>
  </property>  
  <property name="viewResolvers">
      <list>        
        <bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="prefix" value="/WEB-INF/jsp/"/>
          <property name="suffix" value=".jsp"/>
          <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
        </bean>
      </list>
  </property>  
  <property name="defaultViews">
      <list>              
        <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
        <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
          <constructor-arg>
            <bean class="org.springframework.oxm.xstream.XStreamMarshaller" />
          </constructor-arg>
        </bean>        
      </list>
  </property>
 </bean>

the application context security:

<sec:http auto-config='true'  >
  <sec:intercept-url pattern="/login.*"      filters="none"/> 
  <sec:intercept-url pattern="/oauth/**"       access="ROLE_USER" />
  <sec:intercept-url pattern="/v1/**"       access="ROLE_USER" />
  <sec:intercept-url pattern="/request_token_authorized.jsp"  access="ROLE_USER" />
  <sec:intercept-url pattern="/**"        access="ROLE_USER"/>
  <sec:form-login authentication-failure-url ="/login.html"
      default-target-url   ="/login.html" 
      login-page     ="/login.html"
      login-processing-url  ="/login.html" />

  <sec:logout logout-success-url="/index.html" logout-url="/logout.html" />
 </sec:http>

the controller:

@Controller
public class ProfilesController {

 @RequestMapping(value = {"/v1/profiles"}, method = {RequestMethod.GET,RequestMethod.POST})
 public void getProfilesList(@ModelAttribute("response") Response response) {
  ....
 }

}

the request never reaches this controller.

Any ideas?

+3  A: 

Annotations don't do anything until they are processed. You will need

<context:component-scan base-package="path.to.controllers"/>

as a child of your root "beans" tag in order to get Spring to scan for controllers. Spring will scan for controllers in the base-package and it's descendants.

This tags requires

xmlns:context="http://www.springframework.org/schema/context"

and

xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"

in your root "beans" tag.

brendan
Maybe a little late.just to close this thread, this solved the issue
Yaniv Cohen