I'm trying to create a custom route on the gateway, to have control over which microservices the gateway will be able to distribute and it doesn't work.
In this process I use the Registry Eureka, Gateway e microservice Seguranca.
spring boot 3.1.5 java 17
Custom route in GateWay:
server:
port: 8080
spring:
application:
name: gateway
cloud:
gateway:
routes:
- id: seguranca
uri: lb://seguranca
predicates:
- Path=/api/**
eureka:
client:
serviceUrl:
defaultzone: http://localhost:8761/eureka
microservice seguranca:
spring:
application:
name: seguranca
controller
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class AuthenticationController {
private final AuthenticationManager authenticationManager;
private final TokenService tokenService;
@PostMapping("/authenticate")
public ResponseEntity authenticate(@RequestBody @Valid LoginRecord loginRecord) {
var authenticationToken = new UsernamePasswordAuthenticationToken(loginRecord.username(), loginRecord.password());
var authentication = authenticationManager.authenticate(authenticationToken);
var tokenJWT = tokenService.createToken((UserDetailsImpl) authentication.getPrincipal());
return ResponseEntity.ok(new DataTokenJWT(tokenJWT));
}
}
Registry:
eureka:
client:
fetch-registry: false
register-with-eureka: false
instance:
hostname: localhost
server:
port: 8761
spring:
application:
name: service-registry
I added discovery, it works but I realized that custom rotates don't work
discovery:
locator:
enabled: true
lower-case-service-id: true