带有密钥斗篷的Spring Cloud微服务

时间:2020-03-20 06:39:29

标签: spring-boot microservices spring-cloud keycloak spring-cloud-netflix

我有一个Spring Cloud微服务项目,该项目使用Spring Cloud Config Server管理配置,并使用Eureka Server进行服务发现。

在我想用keycloak添加一个新的微服务之前,我的应用程序运行良好。这项新的微服务只是我的Vue前端应用程序的一个剩余API,并且预期由Keycloak处理用户管理。

新服务运行正常,并向Eureka注册。直到,我向项目添加了keycloak依赖项。应用程序不会崩溃或引发任何错误,不会启动,也可以自行注册到Eureka,但是在Spring Boot Admin服务器面板上,我看到该应用程序已关闭。

这是我用于新服务的.properties文件。

eureka.instance.preferIpAddress=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.leaseRenewalIntervalInSeconds=3
eureka.client.eureka-connection-idle-timeout-seconds=3
eureka.client.fetchRegistry=true

spring.boot.admin.client.url=http://localhost:6060
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

server.port=8082

keycloak.auth-server-url=http://localhost:8080/auth
keycloak.realm=microservices
keycloak.resource=microservices-app
keycloak.public-client=true

keycloak.security-constraints[0].authRoles[0]=user
keycloak.security-constraints[0].securityCollections[0].patterns[0]=/*
keycloak.cors=true

这是我对新服务的依赖。

...
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.thymeleaf</groupId>
                <artifactId>thymeleaf</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-spring-boot-starter</artifactId>
        <version>4.8.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.keycloak.bom</groupId>
            <artifactId>keycloak-adapter-bom</artifactId>
            <version>4.8.3.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Spring云版本为Hoxton.SR1

春季启动版本为2.2.2.RELEASE

我试图添加Spring Security并使用KeycloakAuthenticationProvider进行Java配置,但是没有帮助。

在整个项目中,我有许多由Spring Cloud版本或Spring Cloud-Spring Boot Admin交互引起的怪异错误,因此更改版本或向配置文件中添加一个小参数通常可以解决问题,我怀疑此Keycloak问题将是用同样的方法解决了。

1 个答案:

答案 0 :(得分:2)

Spring Boot Admin使用执行器端点,请尝试使其不受保护:

git difftool