0

I am new in spring, therefore maybe my question is stupid! I am trying to add a controller to Spring's Petclinic example. However, the mappings in this controller do not work and I get 404 error. I added the same mapping to the other existing controllers and it works. I want to see what I am doing wrong. Here is my controller:

package org.springframework.samples.petclinic.web;

import java.util.Map;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.stereotype.Controller;

@Controller
public class TwitterController {

    @RequestMapping(value = "/twitter/searchtweets", method = RequestMethod.GET)
        public String initFindForm(Map<String, Object> model) {
        ...
        return "twitter/searchtweets";
    }
}

and here is the component scan definition in my MVC config file:

<context:component-scan
        base-package="org.springframework.samples.petclinic.web"/>

And:

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="contentNegotiationManager" ref="cnManager"/>

    <property name="viewResolvers">
        <list>
             <!-- Default viewClass: JSTL view (JSP with html output) -->
            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <!-- Example: a logical view name of 'vets' is mapped to '/WEB-INF/jsp/vets.jsp' -->
                <property name="prefix" value="/WEB-INF/jsp/"/>
                <property name="suffix" value=".jsp"/>
            </bean>

            <!-- Used here for 'xml' and 'atom' views  -->
            <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
        </list>
    </property>
</bean>

<!-- Simple strategy: only path extension is taken into account -->
<bean id="cnManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="true"/>
    <property name="ignoreAcceptHeader" value="true"/>
    <property name="defaultContentType" value="text/html"/>

    <property name="mediaTypes">
        <map>
            <entry key="html" value="text/html" />
            <entry key="xml" value="application/xml" />
            <entry key="atom" value="application/atom+xml" />
        </map>
    </property>
</bean>

The address: localhost:8081/petclinic/twitter/searchtweets.html returns 404 Error. It's worth mentioning that the jsp file here in: webapp/WEB_INF/jsp/twitter/searchtweets.jsp

Am I missing something?

mahsa.teimourikia
  • 1,664
  • 9
  • 32
  • 64
  • I guess it is due to the `.html` extension in the requested URL. Just try `/twitter/searchtweets` and check . – AllTooSir Jun 07 '13 at 10:10
  • No, it doesn't work, the thing is that if I add the mapping in the current controllers in works fine! I think the controller does not get detected somehow – mahsa.teimourikia Jun 07 '13 at 10:12
  • 2
    .. Do you have this entry in your spring config file ? – ArunM Jun 07 '13 at 10:41
  • Yes, I do. Do you need more info? I can edit the question. – mahsa.teimourikia Jun 07 '13 at 10:57
  • try putting the @RequestMapping("/twitter") just before the class line, and change the @RequestMapping("/twitter/searchtweets") to @RequestMapping("/searchtweets") – CodeChimp Jun 07 '13 at 11:12
  • With further tests I understood that the class is not in the classpath somehow, and that's why it is not getting recognized, is it some kind of bug? what should do to make sure that it gets added to the classpath? – mahsa.teimourikia Jun 07 '13 at 11:19
  • 1
    clean project, rebuild, restart server and redeploy – damian Jun 07 '13 at 12:23

0 Answers0