I am new to spring boot microservice, was able to setup the microservice project successfully. But I tried to implement JWT on the Auth-Service which worked and
@RestController
@RequestMapping("/token")
public class JwtController {
@Autowired
private JwtTokenGenerator jwtGenerator;
//constructor
public JwtController(JwtTokenGenerator jwtGenerator) {
this.jwtGenerator = jwtGenerator;
}
@PostMapping
public String generate(@RequestBody final JwtUser jwtUser) {
return jwtGenerator.generate(jwtUser);
}
}
was able to call it from Postman
which allows me to access the service page
but when I tried to access the same service
@RestController
@RequestMapping("/secure/logon")
public class LogOnController {
@GetMapping
public String logOn() {
return "You are logon successfully";
}
}
from the Eureka discovery service through the Eureka Server
@SuppressWarnings("deprecation")
@RestController
@RequestMapping("/users")
public class UserController {
@Autowired
private RestTemplate restTemplate;
@HystrixCommand(fallbackMethod = "fallback", groupKey = "Hello",
commandKey = "hello",
threadPoolKey = "helloThread")
@PostMapping(value = "/index")
public String token() {
String url = "http://user-service/token";
return restTemplate.getForObject(url, String.class);
}
@GetMapping(value = "/logon")
public String index() {
String url = "http://user-service/secure/logon";
return restTemplate.getForObject(url, String.class);
}
public String fallback(Throwable hystrixCommand) {
return "User-Service Failed ";
}
}
I get error
Please what is the best way to access the auth-service through the Eureka-discovery service.