简体   繁体   English

使用Spring Restful Web Service时遇到org.springframework.web.servlet.PageNotFound.noHandlerFound错误

[英]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;
            }
        );
    };
}]);

web.xml web.xml中

<?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>

Controller 调节器

@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.

相关问题 获取org.springframework.web.servlet.PageNotFound noHandlerFound错误 - Getting org.springframework.web.servlet.PageNotFound noHandlerFound error 尝试在Eclipse中运行Spring MVC代码时,org.springframework.web.servlet.PageNotFound noHandlerFound错误 - org.springframework.web.servlet.PageNotFound noHandlerFound error while trying running a Spring MVC code in eclipse org.springframework.web.servlet.PageNotFound noHandlerFound - org.springframework.web.servlet.PageNotFound noHandlerFound org.springframework.web.servlet.PageNotFound noHandlerFound 得到这个 - org.springframework.web.servlet.PageNotFound noHandlerFound getting this Spring MVC-org.springframework.web.servlet.PageNotFound noHandlerFound - Spring mvc - org.springframework.web.servlet.PageNotFound noHandlerFound org.springframework.web.servlet.PageNotFound noHandlerFound春天 - org.springframework.web.servlet.PageNotFound noHandlerFound spring eclipse中的org.springframework.web.servlet.PageNotFound noHandlerFound - org.springframework.web.servlet.PageNotFound noHandlerFound in eclipse org.springframework.web.servlet.PageNotFound noHandlerFound错误-已经尝试了所有方法,仍然无法使用:/ - org.springframework.web.servlet.PageNotFound noHandlerFound Error - Already tried everything, still not working :/ 我的Spring Rest Web服务无法正常工作,出现错误“ org.springframework.web.servlet.PageNotFound handleNoSuchRequestHandlingMethod” - My spring rest web service not working, I got error “org.springframework.web.servlet.PageNotFound handleNoSuchRequestHandlingMethod” 作为org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported获取错误 - Getting Error as org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM