diw*_*att 3 spring-boot keycloak
问题陈述
我无法通过 Spring Boot 项目构建,我想通过它来保护我的应用程序。钥匙斗篷。
预期产出
项目构建成功,当我点击其余 URL 时,它将重定向到密钥隐藏页面进行身份验证。
员工休息控制器
@RestController
public class EmployeeRestController {
@GetMapping(path = "/username")
public String getAuthorizedUserName() {
return "Username Returned";
}
@GetMapping(path = "/roles")
public String getAuthorizedUserRoles() {
return "Roles Returned";
}
}
Run Code Online (Sandbox Code Playgroud)
启动
@SpringBootApplication
public class Startup {
public static void main(String[] args) {
SpringApplication.run(Startup.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
应用属性
server.port=8085
keycloak.realm=wow
keycloak.auth-server-url=http://localhost:8180/auth
keycloak.resource=wow-client
keycloak.public-client=true
keycloak.securityConstraints[0].authRoles[0]=user
keycloak.securityConstraints[0].securityCollections[0].patterns[0]=/*
Run Code Online (Sandbox Code Playgroud)
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.keycloak/keycloak-spring-boot-starter -->
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
<version>7.0.0</version>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
错误日志
2019-09-16 17:44:24.525 INFO 10396 --- [ main] com.diwakar.Startup : Starting Startup on diwakarb with PID 10396 (started by diwakarb in E:\DB Godam\Sample-KeyCloak-Project)
2019-09-16 17:44:24.527 INFO 10396 --- [ main] com.diwakar.Startup : No active profile set, falling back to default profiles: default
2019-09-16 17:44:25.419 WARN 10396 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.keycloak.adapters.springboot.KeycloakAutoConfiguration': Unsatisfied dependency expressed through method 'setKeycloakSpringBootProperties' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2019-09-16 17:44:25.429 INFO 10396 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-16 17:44:25.531 ERROR 10396 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method setKeycloakSpringBootProperties in org.keycloak.adapters.springboot.KeycloakBaseSpringBootConfiguration required a bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' that could not be found.
Action:
Consider defining a bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' in your configuration.
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
注意:请考虑正确配置密钥披风
小智 5
我在使用 springboot-2.2.0/keycloak-7.0.1 时遇到了同样的问题。我将 bean KeycloakSpringBootConfigResolver 移动到另一个配置文件并且它可以工作。
@Configuration
public class BeanKeycloakConfiguration {
@Bean
public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
}`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1426 次 |
| 最近记录: |