Stack Exchange
404 on simple Spring REST service
I am trying to access a REST service on:
http://localhost:8080/events

Im getting a 404 using this adres, and i dont know why. Im trying to return JSON with GET.
Here is controller:
package com.app.eventapp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
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.ResponseBody;

import lukpra.jba.entity.Event;
import lukpra.jba.service.EventService;

@Controller
public class EventController {

    @Autowired
    private EventService eventService;

    @RequestMapping(value = "/events" , method = RequestMethod.GET)
    public String events(Model model){
        model.addAttribute("events", eventService.findAll());
        return "events";
    }

    public @ResponseBody ResponseEntity <List<Event>> getEvents(){
        List<Event> events = eventService.findAll();        
        return new ResponseEntity<List<Event>>( events, HttpStatus.OK);
    }

    @RequestMapping(value = "/test",  method = RequestMethod.GET)
    public ResponseEntity<List<Event>> getRestEvents(){
        List<Event> events = eventService.findAll();        
        return new ResponseEntity<List<Event>>( events, HttpStatus.OK);
    }
}

And my web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>event_app</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.html</url-pattern>
        <url-pattern>*.htm</url-pattern>
        <url-pattern>*.json</url-pattern>
        <url-pattern>*.xml</url-pattern>
    </servlet-mapping>

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

</web-app>

and dispatcher:
<context:component-scan base-package="com.app.eventapp"></context:component-scan>


    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/defs/general.xml</value>
            </list>
        </property>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
         <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
    </bean>
</beans>

Problem must be somewhere in the mapping. I can display events page with data from controller without any problem, so this works for sure.
I dont have any error logs in jetty console. It might be url path, but adding:
<url-pattern>/</url-pattern>

breaks the app.  
UPDATE:
my dispatcher accepts links with formats that end with eg: "*.json". So i have tried adding this extension to mapping:
@RequestMapping(value="/test.json", produces = {

And now i recive HTTP ERROR 406 Problem accessing /test.json. Reason: Not Acceptable
There are also logs of hibernate doing select when this is called so this is good sign.

In order to use a controller in your rest  don't you have to mention @rest controller annotation in your controller?

@RestController is @Controller + @ResponseBody, so no i dont have to.

Can you see how your response looks in the browser console? Because as per your comment you are seeing in the hibernate logs the query is being executed.

I am not familiar with Jetty but I think it works like tomcat. In tomcat, you need to reset the context path to "/" so that you can ignore the your project name in the URL. You can check this website out to reset the context path. Hope this helps.
