Announcement Announcement Module
Collapse
No announcement yet.
Spring Web Annotations - HTTP 404 Not Found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Web Annotations - HTTP 404 Not Found

    Hi,

    I'm trying to convert the sample InventoryController to use Spring annotations but keep hitting problems.

    My InventoryController is defined as below.

    When I deploy the app, I get a debug entry saying the controller has been found and mapped to the correct URL:

    Code:
    INFO : org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/home.htm] onto handler 'inventoryController'
    However when I try to access /springapp/home.htm in my browser I can a HTTP 404 not found error.

    Can anyone point me in the correct direction?

    Thanks.

    Code:
    @Controller
    @RequestMapping("/home.htm")
    public class InventoryController {
    
    	protected final Log logger = LogFactory.getLog(getClass());
    
    	@Autowired
    	private ProductManager productManager;
    
    	@RequestMapping(method = RequestMethod.GET)
    	public ModelAndView handleRequest() {
    		String now = (new java.util.Date()).toString();
    		logger.info("returning hello view with " + now);
    
    		Map<String, Object> myModel = new HashMap<String, Object>();
    		myModel.put("now", now);
    		myModel.put("products", this.productManager.getProducts());
    
    		return new ModelAndView("hello", "model", myModel);
    	}
    
    	public void setProductManager(ProductManager productManager) {
    		this.productManager = productManager;
    	}
    
    }
    Last edited by davey; Feb 24th, 2011, 07:43 AM.

  • #2
    Can you post your config file? What does your view resolver look like?

    Comment


    • #3
      Hi,

      Thanks for your help.

      I've been looking at this all day trying to figure it out and as soon as I've come to reply I've noticed that the url-pattern for my servlet was set to /.htm rather than *.htm

      Once I've changed that, its all working.

      Comment

      Working...
      X