Java 使用Spring Restful web服务时,获取org.springframework.web.servlet.PageNotFound.noHandlerFound时出错
我正在使用SpringRESTfulWebService和AngularJS。我正在尝试连接后端代码,但无法连接。我不知道我到底错在哪里 这是我的角度代码:Java 使用Spring Restful web服务时,获取org.springframework.web.servlet.PageNotFound.noHandlerFound时出错,java,angularjs,spring,Java,Angularjs,Spring,我正在使用SpringRESTfulWebService和AngularJS。我正在尝试连接后端代码,但无法连接。我不知道我到底错在哪里 这是我的角度代码: app.constant('REST_URI', 'http://localhost:8181/rest/'); app.factory('FeedbackService',['$http', 'REST_URI', function ($http, REST_URI) { const addFeedbackAPI = REST
app.constant('REST_URI', 'http://localhost:8181/rest/');
app.factory('FeedbackService',['$http', 'REST_URI', function ($http, REST_URI) {
const addFeedbackAPI = REST_URI + 'feedback/addFeedback';
var addFeedback = function(feedbackData){
return $http.post(addFeedbackAPI, feedbackData);
};
return {
addFeedback : addFeedback
};
}]);
app.controller('feedbackController', ['$scope', 'FeedbackService', function ($scope, FeedbackService) {
$scope.feedbackData = {};
$scope.addFeedback = function () {
$scope.feedbackData.registerDate = new Date();
FeedbackService.addFeedback($scope.feedbackData).then(
function (successResponse) {
$scope.feedbackResponse = successResponse;
},
function (errorResponse) {
$scope.feedbackResponse = errorResponse;
}
);
};
}]);
web.xml
但我在日志中发现404错误:
控制台:
http://localhost:8181/rest/feedback/addFeedback 404 ()
服务器:
2017年2月1日10:05:49.339警告[http-nio-8181-exec-9]org.springframework.web.servlet.PageNotFound.nohandler在名为“springrest”的DispatcherServlet中未找到URI为[/rest/feedback/addFeedback]的http请求的映射
使用
@RestController(value=“/feedback/”)
而不是@RestController(value=“/rest/feedback/”)
因为您已经在web.xml
中使用了/rest/*
,所以您不需要在java控制器中给出这一点
@RestController(value = "/rest/feedback/")
public class FeedbackController {
@Autowired
private FeedbackService feedbackService;
@RequestMapping(value = "addFeedback", method = RequestMethod.POST)
public long addFeedback(@RequestBody Feedback feedback) {
return feedbackService.addFeedback(feedback);
}
}
http://localhost:8181/rest/feedback/addFeedback 404 ()