Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 方法POST不支持Netflix Eureka和ZUUL_Java_Spring Boot_Netflix Zuul_Netflix Eureka - Fatal编程技术网

Java 方法POST不支持Netflix Eureka和ZUUL

Java 方法POST不支持Netflix Eureka和ZUUL,java,spring-boot,netflix-zuul,netflix-eureka,Java,Spring Boot,Netflix Zuul,Netflix Eureka,我正在用JAVA创建一个Rest控制器。当我在本地运行应用程序时,我可以执行POST操作。然后我创建一个JAR,然后将其部署到服务器上。请注意,我使用Netflix Eureka进行服务发现,使用zuul作为API网关。应用程序在服务器上开始正常运行,并在Eureka服务器中注册。但当我使用POST服务时,它给了我一个错误:405方法POST不受支持 控制器类 import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.

我正在用JAVA创建一个Rest控制器。当我在本地运行应用程序时,我可以执行POST操作。然后我创建一个JAR,然后将其部署到服务器上。请注意,我使用Netflix Eureka进行服务发现,使用zuul作为API网关。应用程序在服务器上开始正常运行,并在Eureka服务器中注册。但当我使用POST服务时,它给了我一个错误:405方法POST不受支持

控制器类

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bp.budgetpulse.domain.FeedBackEmployeeDetails;
import com.bp.budgetpulse.service.FeedBackService;


@RestController
@RequestMapping(value = "/api/v1")
public class FeedBackController {

    @SuppressWarnings("unused")
    private final Logger logger = LoggerFactory.getLogger(FeedBackService.class);

    @Autowired
    private FeedBackService feedbackService;

    /**
     * This method to save the feedback details
     * 
     * @param feedbackDetails
     * @param userName
     * @return response
     */
    @RequestMapping(value = "/saveEmployeeFeedbackDetails", method = RequestMethod.POST)
    public String saveEmployeeFeedbackDetails(@RequestBody FeedBackEmployeeDetails empFeedbackDetails) {
        return feedbackService.saveEmployeeFeedbackDetails(empFeedbackDetails);
    }

    /**
     * 
     * this method to get the feedback details
     * 
     * @return feedback details
     */
    @RequestMapping(value = "/getFeedBackDetails/{email}", method = RequestMethod.GET)
    public FeedBackEmployeeDetails getFeedBackDetails(@PathVariable String email) {
        return feedbackService.getFeedBackDetails(email);
    }
}

Netflix Eureka和ZUUL支持POST方法。Netflix Eureka和ZUUL不对API方法施加任何限制。以下是我编写的控制器代码示例,在Netflix Eureka和ZUUL环境中运行时不会出现任何问题:

import com.aj.gradingservice.model.Grade;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/")
public class GradeController {

    private static final Logger logger = LoggerFactory.getLogger(GradeController.class);

    @RequestMapping(value = "ping", method = RequestMethod.GET)
    public ResponseEntity<Map<String, String>> ping() {
        Map<String, String> response = new HashMap<>();
        response.put("message", "pong");
        return new ResponseEntity<>(response, HttpStatus.OK);
    }

    @RequestMapping(value = "grades", method = RequestMethod.GET)
    public ResponseEntity<List<Grade>> getGrades() {
        logger.info("In GradeController.getGrades(), fetching list of grades");
        List<Grade> grades = new ArrayList<>();
        grades.add(new Grade(1, "P001", "A+"));
        grades.add(new Grade(2, "C001", "A"));
        grades.add(new Grade(3, "M001", "B+"));
        return new ResponseEntity<>(grades, HttpStatus.OK);
    }

    @RequestMapping(value = "grade", method = RequestMethod.POST,
            consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Grade> createGrade(@RequestBody Grade grade) {
        logger.info("Request received is: " + grade );
        Grade gradeCreated = new Grade(grade.getId(),grade.getStudentId(),grade.getGrade());
        return new ResponseEntity<>(gradeCreated, HttpStatus.OK);
    }
}
import com.aj.gradingservice.model.Grade;
导入org.slf4j.Logger;
导入org.slf4j.LoggerFactory;
导入org.springframework.http.HttpStatus;
导入org.springframework.http.MediaType;
导入org.springframework.http.ResponseEntity;
导入org.springframework.web.bind.annotation.RequestBody;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.RestController;
导入java.util.ArrayList;
导入java.util.HashMap;
导入java.util.List;
导入java.util.Map;
@RestController
@请求映射(“/”)
公共班级成绩控制员{
私有静态最终记录器Logger=LoggerFactory.getLogger(GradeController.class);
@RequestMapping(value=“ping”,method=RequestMethod.GET)
公众反应平(){
Map response=newhashmap();
回应。把(“信息”、“乒乓球”);
返回新的ResponseEntity(response,HttpStatus.OK);
}
@RequestMapping(value=“grades”,method=RequestMethod.GET)
公众反应(成绩){
info(“在GradeController.getGrades()中,获取等级列表”);
列表等级=新的ArrayList();
增加(新的等级(1,“P001”,“A+”));
增加(新职系(2,“C001”、“A”);
增加(新职系(3,“M001”,“B+”));
返回新的响应状态(等级,HttpStatus.OK);
}
@RequestMapping(value=“grade”,method=RequestMethod.POST,
consumes=MediaType.APPLICATION\u JSON\u VALUE,products=MediaType.APPLICATION\u JSON\u VALUE)
公共响应度createGrade(@RequestBody-Grade){
logger.info(“收到的请求为:“+等级”);
Grade Grade CREATED=新成绩(Grade.getId()、Grade.getStudentId()、Grade.getGrade());
返回新的响应属性(gradeCreated,HttpStatus.OK);
}
}

我写了一篇博客文章,详细解释了如何设置Netflix Eureka和Zuul环境,GitHub中有端到端的工作代码。请检查:

您是否能够解决此问题。?