嗨,我最近在假装客户端和eureka学习spring云,但是在打开我的web应用程序时遇到了困难,我得到的是
读取RoomReservationService#getRoomReservationsForDate(String)的
feign.FeignException$NotFound:状态404
and The error at com.frankmoley.webapp.reservation.ReservationController.getReservations(ReservationController.java:42)
这是我的RoomReservationService代码
package com.frankmoley.webapp.reservation.client;
import com.frankmoley.webapp.reservation.domain.Room;
import com.frankmoley.webapp.reservation.domain.RoomReservation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* Created by frankmoley on 5/23/17.
*/
@FeignClient("RESERVATIONBUSINESSSERVICES")
public interface RoomReservationService {
@RequestMapping(value = "/rooms", method = RequestMethod.GET)
public List<Room> getAllRooms(@RequestParam(name="roomNumber", required=false)String roomNumber);
@RequestMapping(value="/roomReservations/{date}", method=RequestMethod.GET)
public List<RoomReservation> getRoomReservationsForDate(@PathVariable("date") String date);
}还有我的ReservationController
package com.frankmoley.webapp.reservation;
import com.frankmoley.webapp.reservation.client.RoomReservationService;
import com.frankmoley.webapp.reservation.domain.Room;
import com.frankmoley.webapp.reservation.domain.RoomReservation;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;
@Controller
@RequestMapping(value="/reservations")
public class ReservationController {
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private final RoomReservationService roomReservationService;
@Autowired
public ReservationController(RoomReservationService roomReservationService){
super();
this.roomReservationService = roomReservationService;
}
@RequestMapping(method= RequestMethod.GET)
public String getReservations(@RequestParam(value="date", required=false)String dateString, Model model){
String date = dateString;
if(StringUtils.isBlank(dateString)){
date = this.createTodayDateString();
}
List<Room> rooms = this.roomReservationService.getAllRooms("P1");
List<RoomReservation> roomReservations = this.roomReservationService.getRoomReservationsForDate(date);
model.addAttribute("roomReservations", roomReservations);
return "reservations";
}
public String createTodayDateString(){
return DATE_FORMAT.format(new Date());
}
}我到处找但找不到答案请帮帮我
发布于 2019-09-25 03:55:18
因为它是404,所以它找不到配置客户机的url。看起来你需要为假客户端配置url。配置可以通过应用程序yaml的
例如application.yaml
RESERVATIONBUSINESSSERVICES:
url: http:localhost:8080/reservationbusinessservice/RoomReservationService
@FeignClient(name = "RESERVATIONBUSINESSSERVICES", url = "${RESERVATIONBUSINESSSERVICES.url}", 发布于 2020-04-12 03:46:35
您是否使用servlet上下文路径,如果使用它,则需要在虚拟客户端方法中包含上下文路径。
https://stackoverflow.com/questions/58090776
复制相似问题