嗨,我最近学习了spring cloud with feign client和Eureka ,但是在打开我的web应用程序时遇到了麻烦。
FeignException$NotFound:状态404阅读RoomReservationService#getRoomReservationsForDate(String)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());
}
}
型
我一直在寻找任何地方,但无法找到答案,请帮助我
2条答案
按热度按时间piah890a1#
由于它是404,它找不到配置客户端的URL。看起来你需要为假客户端配置URL。配置可以通过应用程序yaml的
例如,应用程序.yaml
字符串
客房预订服务
型
rseugnpd2#
你是否使用servlet上下文路径,如果你使用它,你需要在Feign Client方法中包含上下文路径