[英]Getting org.springframework.web.servlet.PageNotFound.noHandlerFound error, while using Spring Restful Web Service
I am using spring restful webservice along with angular JS. 我正在使用spring restful webservice和angular JS。 I am trying to connect with my backend code but could not able to do so.
我正在尝试连接我的后端代码,但无法实现。 I am not able to figure out where exactly I am going wrong.
我无法弄清楚我到底要去哪里。
Here is my angular code : 这是我的角度代码:
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;
}
);
};
}]);
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/rootApplicationContext.xml</param-value>
</context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<servlet>
<servlet-name>springrest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/webApplicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
@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);
}
}
But I am getting 404 error in logs : 但是我在日志中收到404错误:
console : 安慰 :
http://localhost:8181/rest/feedback/addFeedback 404 ()
server : 01-Feb-2017 10:05:49.339 WARNING [http-nio-8181-exec-9] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/rest/feedback/addFeedback] in DispatcherServlet with name 'springrest' 服务器:2017年2月1日10:05:49.339警告[http-nio-8181-exec-9] org.springframework.web.servlet.PageNotFound.noHandlerFound找不到具有URI [/ rest / feedback / addFeedback的HTTP请求的映射]在DispatcherServlet中,名称为“ springrest”
use @RestController(value = "/feedback/")
使用
@RestController(value = "/feedback/")
instead of @RestController(value = "/rest/feedback/")
而不是
@RestController(value = "/rest/feedback/")
because you have already used /rest/*
in your web.xml
you need not to give this in java controller. 因为您已经在
web.xml
使用了/rest/*
,所以不需要在Java控制器中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.