无法访问Controller映射的路由

时间:2017-04-11 19:06:10

标签: spring tomcat url-routing

我正在尝试在@Controller类中映射路由/时钟,但我在本地测试时得到的错误是404,我正在使用apache tomcat 8并且模块已同步。

以下是我的应用程序类的链接:

@EntityScan(basePackages = "br.ufpe.nti.model")
@EnableJpaRepositories(basePackages = "br.ufpe.nti.controller.repository")
@SpringBootApplication(scanBasePackages = "br.ufpe.nti")
public class SmartClockApplication {

    public static void main(String[] args) {
        SpringApplication.run(SmartClockApplication.class, args);
    }
}

控制器在这里:

@Controller
public class Routes
{
    @RequestMapping(value = "/clock", method = RequestMethod.GET)
    public ResponseEntity<JSONObject> getClock()
    {
        DateFormat dateAndTime = new SimpleDateFormat("YYYY/MM/DD HH:mm:ss");
        DateFormat time = new SimpleDateFormat("HH:mm");
        Calendar cal = Calendar.getInstance();

        final HttpHeaders httpHeaders= new HttpHeaders();
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        double angleHour = 0.5 * (60 * (cal.get(Calendar.HOUR) + 1) + cal.get(Calendar.MINUTE));
        double angleMinute = 6 * cal.get(Calendar.MINUTE);
        double angle = Math.abs(angleHour - angleMinute);

        JSONObject response = new JSONObject();
        try {
            response.put("id", null);
            response.put("time", time.format(cal.getTime()));
            response.put("createdAt", dateAndTime.format(cal));
            response.put("angle", angle);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return new ResponseEntity<JSONObject>(response, httpHeaders , HttpStatus.OK);
    }
}

我被告知tomcat应该在控制台中显示有关路由映射的消息,但是没有这样的消息。

0 个答案:

没有答案