0

I have spring project with web.xml configuration

<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>

Here is my servlet-context.xml

resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**" />

<default-servlet-handler/> 

<context:component-scan base-package="pk.training.basitMahmood.web.controller" />

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jspx" />
</beans:bean>

Here is my controller

@RequestMapping("/contacts")
@Controller
public class ContactController {

    final Logger logger = LoggerFactory.getLogger(ContactController.class);

    @Autowired
    private ContactService contactService;

    @RequestMapping(method = RequestMethod.GET)
    public String list(Model uiModel) {

        logger.info("Listing contacts");
        List<Contact> contacts = contactService.findAll();
        uiModel.addAttribute("contacts", contacts);
        logger.info("No. of contacts: " + contacts.size());

        return "contacts/list";

    }

} //end of class ContactController

Now when i select run on server then i get the following page

enter image description here

But when i change the url to http://localhost:9090/ch17_i18nSupport/contacts then i get the error that

enter image description here

I have list.jspx in my contacts folder. Why i am getting not found error?

Thanks

8
  • What happens if you add in your servlet-context.xml the bean <bean name="/contacts" class="pk.training.(...).ContactController"></bean>? Commented Jun 6, 2013 at 10:45
  • I am getting errors in my ContactController class. I have import statements import pk.training.basitMahmood.domain.Contact; import pk.training.basitMahmood.service.ContactService; but code says unresolve imports, don't know why ... Commented Jun 6, 2013 at 11:08
  • 2
    done. I was missing <annotation-driven /> tag in my servlet-context.xml. Now everything is working fine :) Commented Jun 6, 2013 at 11:57
  • 2
    No adapter for handler indicates that the @RequestMapping methods in your controller aren't being picked up. Do you have a <mvc:annotation-driven /> tag in your servlet-context.xml? Commented Jun 6, 2013 at 12:08
  • 1
    One of you could add this an answer and mark it solved. Commented Jun 6, 2013 at 19:44

1 Answer 1

1

Although this was solved by Basit in the comments, I've also added it as an answer:

No adapter for handler indicates that the @RequestMapping methods in your controller aren't being picked up. Do you have a <mvc:annotation-driven /> tag in your servlet-context.xml?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.