I have a problem about sending a request and get user information from Keycloak running in Docker in Spring Cloud Example.
Here is my Keycloak example defined in user service.
@Configuration
public class KeycloakConfig {
public final static String serverUrl = "http://keycloak:8181";
public final static String realm = "master";
public final static String clientId = "spring-boot-microservice-keycloak";
public final static String clientSecret = "l4ToCS7CfEA3uR3BH4M9YzhxXNrzymOh";
final static String userName = "admin";
final static String password = "admin";
@Bean
public KeycloakConfigResolver keycloakConfigResolver(){
return new KeycloakSpringBootConfigResolver();
}
@Bean
public Keycloak keycloak(){
return Keycloak.getInstance(serverUrl,
realm,
userName,
password,
clientId,
clientSecret);
}
}
Here is my user service properties file shown below.
#spring.datasource.url=jdbc:mysql://localhost:3306/springbootuser?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.url=jdbc:mysql://database:3306/springbootuser?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.username=springmicroserviceuser
spring.datasource.password=111111
# Define hibernate settings (JPA / Hibernate properties)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
server.port=9000
spring.application.name=user-service
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.client.serviceUrl.defaultZone=http://eurekaserver:8761/eureka
keycloak.realm=master
#keycloak.auth-server-url=http://localhost:8181
keycloak.auth-server-url=http://keycloak:8181
keycloak.ssl-required=external
keycloak.resource=spring-boot-microservice-keycloak
keycloak.bearer-only=true
keycloak.public-client=true
When I send a request http://localhost:8600/api/v1/users/signup
to user service, I had a problem in Keycloak.
Here are errors shown in the console from user service.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw excepti
on [Request processing failed; nested exception is javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: org.apache.http.conn.HttpHostConnectException: Connect to
keycloak:8181 [keycloak/172.19.0.3] failed: Connection refused (Connection refused)] with root cause
How can I fix it?
Here is the project link : Link