You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Keycloak注册到Spring Eureka Server服务发现中心

How to Register Keycloak with Eureka Discovery Service

Great to hear your Eureka Server and user-service registration are working flawlessly! Getting Keycloak registered with Eureka is straightforward—let’s break down the steps based on how you’re running Keycloak:

If your keycloak-authorization-service is a Spring Boot application (using the Keycloak Spring Boot Starter, for example), follow these steps:

  1. Add Eureka Client Dependency
    Add the Spring Cloud Eureka Client dependency to your build file. For Maven, add this to your pom.xml:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    

    For Gradle, add this to your build.gradle:

    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    
  2. Enable Discovery Client
    Add the @EnableDiscoveryClient annotation to your Keycloak service’s main application class, just like you did for user-service:

    @SpringBootApplication
    @EnableDiscoveryClient
    public class KeycloakAuthorizationServiceApplication {
        public static void main(String[] args) {
            SpringApplication.run(KeycloakAuthorizationServiceApplication.class, args);
        }
    }
    
  3. Configure Eureka Settings
    Update your application.properties (or application.yml) with Eureka registration details. Adjust the port and hostname to match your Keycloak setup:

    spring.application.name=keycloak-authorization-service
    server.port=8080 # Use your Keycloak service's actual port
    eureka.instance.hostname=localhost
    eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka
    
    # Optional: If using HTTPS for Keycloak, add these settings
    eureka.instance.nonSecurePortEnabled=false
    eureka.instance.securePortEnabled=true
    eureka.instance.securePort=8443 # Your Keycloak HTTPS port
    

Option 2: Standalone Keycloak Server (Non-Spring Boot)

If you’re running the standard standalone Keycloak distribution (WildFly-based), you can register it with Eureka using Eureka’s REST API:

  1. Register the Instance via HTTP POST
    Send a POST request to your Eureka Server’s registration endpoint with an XML payload describing your Keycloak instance:

    POST http://localhost:8000/eureka/apps/KEYCLOAK-AUTHORIZATION-SERVICE
    Content-Type: application/xml
    
    <instance>
        <hostName>localhost</hostName>
        <app>KEYCLOAK-AUTHORIZATION-SERVICE</app>
        <ipAddr>127.0.0.1</ipAddr>
        <status>UP</status>
        <port enabled="true">8080</port>
        <securePort enabled="false">8443</securePort>
        <metadata>
            <instanceId>keycloak-authorization-service:8080</instanceId>
        </metadata>
    </instance>
    
  2. Maintain Heartbeat
    Eureka requires regular heartbeats to keep the instance marked as UP. Send a PUT request every 30 seconds (default Eureka lease renewal interval) to:

    PUT http://localhost:8000/eureka/apps/KEYCLOAK-AUTHORIZATION-SERVICE/keycloak-authorization-service:8080
    

    You can automate this with a cron job, shell script, or a monitoring tool to avoid manual updates.

Additional Notes

  • If your Eureka Server is secured with authentication, update the eureka.client.serviceUrl.defaultZone to include credentials: http://username:password@localhost:8000/eureka
  • Ensure the spring.application.name matches the service name you want displayed in the Eureka dashboard
  • Double-check that port numbers match your actual Keycloak service configuration

Once you’ve completed these steps, refresh your Eureka dashboard—you should see keycloak-authorization-service listed alongside user-service!

内容的提问来源于stack exchange,提问作者Muhammed Ozdogan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 18:27:38