I am trying to set up routing in Gateway in the properties I prescribe the address and where to redirect, I can not understand the logic of the work.
server: port: 8081 eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka spring: application: name: gateway cloud: gateway: discovery: locator: enabled: true routes: - id: servicetest uri: http://localhost:8080/ predicates: - Path=/services/** - id: service-student uri: http://localhost:8082/ predicates: - Path=/**
ServiceTest
spring.application.name=ServiceTest server.port=8080
@RestController public class TestController {
@GetMapping("/hello") public String hello(){ return "Controller is work from " + this.getClass().getName().toString(); }
}
service-student
spring.datasource.url=jdbc:postgresql://localhost:5432/spring spring.datasource.username=postgres spring.datasource.password=root spring.jpa.generate-ddl=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true server.port=8082 spring.application.name=service-student eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka @Slf4j @RestController @RequestMapping("/") public class TeacherController { @Autowired TeacherRepository teacherRepository; @GetMapping("/teachers") public ResponseEntity<List<Teacher>> findAllTeachers(){ List<Teacher> groups = teacherRepository.findAll(); if(groups.isEmpty()){ return new ResponseEntity<>(groups, HttpStatus.NO_CONTENT); } return new ResponseEntity<>(groups,HttpStatus.OK); }
When accessing via http://localhost:8081/teachers
, everything is OK, JSON is returned from the desired service (id service-student). But if you do Path=/services/**
and try to reach http://localhost:8081/services/hello
is no access. How to create a config?
/services/
. If you do not need it on the second service, then you should use therewritepath
filter - Chubatiy