我正与山云合作。 我的春boot应用有四处服务:college-service
,student-service
,eureka-server
和api-gateway
。 我正试图打电话到college-service
和student-service
。 虽然Im打着My college-service
,但从APIC/ 工作罚款但<代码>student-service的网关没有工作。 虽然我试图获得<代码>student-serivice,但我发现有错误404
。 我在春云中翻一番。 下面是我的法典。
www.un.org/Depts/DGACM/index_russian.htm 在上次午餐时,我获得404
URL | Status |
---|---|
http://localhost:9001/college/CLG01 | 200 OK |
http://localhost:9002/college/student/CLG01 | 200 OK |
http://localhost:9003/college/CLG01 | 200 OK |
http://localhost:9003/college/student/CLG01 | 400 Not Found |
Colleger Service
public class College {
private String clgId;
private String clgName;
private String clgCity;
List<Student> students;
public College(String clgId, String clgName, String clgCity, List<Student> students) {
this.clgId = clgId;
this.clgName = clgName;
this.clgCity = clgCity;
this.students = students;
}
public College(String clgId, String clgName, String clgCity) {
this.clgId = clgId;
this.clgName = clgName;
this.clgCity = clgCity;
}
// getter and setter
}
public class Student {
private Long stId;
private String stName;
private String stEmail;
private String clgId;
public Student(Long stId, String stName, String stEmail, String clgId) {
super();
this.stId = stId;
this.stName = stName;
this.stEmail = stEmail;
this.clgId = clgId;
}
// getter and setter
}
@RestController
@RequestMapping("/college")
public class CollegeController {
@Autowired
private CollegeService collegeService;
@Autowired
private RestTemplate restTemplate;
@RequestMapping(value = "/{clgId}", method = RequestMethod.GET)
public ResponseEntity<College> getColleges(@PathVariable("clgId") String clgId) {
College college = collegeService.getCollege(clgId);
List student = restTemplate.getForObject("http://student-service/college/student/" + college.getClgId(),
List.class);
college.setStudents(student);
return ResponseEntity.ok(college);
}
}
server:
port: 9001
spring:
application:
name: college-service
eureka:
instance:
hostname: localhost
Student Service
Student Controller
public class Student {
private Long stId;
private String stName;
private String stEmail;
private String clgId;
public Student(Long stId, String stName, String stEmail, String clgId) {
super();
this.stId = stId;
this.stName = stName;
this.stEmail = stEmail;
this.clgId = clgId;
}
// getter and setter
}
@RestController
@RequestMapping("/college")
public class StudentCotroller {
@Autowired
private StudentService studentService;
@RequestMapping(value = "/student/{clgId}", method = RequestMethod.GET)
public ResponseEntity<List<Student>> getStudents(@PathVariable("clgId") String clgId) {
return ResponseEntity.ok(studentService.getStudents(clgId));
}
}
server:
port: 9002
spring:
application:
name: student-service
eureka:
instance:
hostname: localhost
Eureka Server
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
API Gateway Service
server:
port: 9003
eureka:
instance:
hostname: localhost
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
- id: college-service
uri: lb://college-service
predicates:
- Path=/college/**
- id: student-service
uri: lb://student-service
predicates:
- Path=/student/**