spring-security - 黄瓜测试,jhipster 和 oauth:找不到 ClientRegistrationRepository bean
问题描述
当我将其配置为使用 oauth2 时,我在 khipster 项目中运行 Cucumber 测试时遇到问题(我也可以使用 jhipster 重现它)。
我使用以下配置文件创建项目(我称之为mono.jdl):
application {
config {
applicationType monolith
authenticationType oauth2
baseName helloworld
buildTool maven
packageName com.example.helloworld
testFrameworks [cucumber]
}
entities *
}
我使用命令生成项目:khipster import-jdl mono.jdl
.
我创建了一个非常简单的 Cucumber 测试。我创建了一个功能文件(src/test/features/kuku/kuku.feature):
Feature: just a test
Scenario: my scenario
And one two three
和一个包含步骤的文件(src/test/kotlin/com/example/helloworld/cucumber/stepdefs/KukuStepDefs.kt):
package com.example.helloworld.cucumber.stepdefs
import io.cucumber.java.en.When
class KukuStepDefs : StepDefs() {
@When("one two three")
fun magic() {
println("four five six")
}
}
我尝试使用命令运行集成测试./mvnw integration-test
。但是,它失败并出现以下错误:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.example.helloworld.web.rest.LogoutResource required a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'clientRegistrationRepository' in 'OAuth2ClientRegistrationRepositoryConfiguration' not loaded because OAuth2 Clients Configured Condition registered clients is not available
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' in your configuration.
我该如何解决这个问题?
解决方案
解决方法是找到CucumberContextConfiguration类。它包含这样的注释:
@ContextConfiguration(classes = [HelloworldApp::class])
我们必须将其更改为:
import com.example.helloworld.config.TestSecurityConfiguration
(...)
@ContextConfiguration(classes = [HelloworldApp::class, TestSecurityConfiguration::class])
推荐阅读
- scala - 为什么我的 spark 作业在 collectasMap 时被阻塞
- python - 订购seaborn箱线图的y轴?
- python - 在 Seaborn 图中获取 LaTeX 符号,而不会弄乱 Pandas 查询
- r - 为什么我的 for 循环不是每次都重新分配数据帧?
- c# - 同一类型的多个关系
- asp.net-core-webapi - 使用 PutAsync 将数据(带寄存器的模型)发送到 API,但仅在没有注册的情况下到达 Id
- vb6 - 如何在带有数据库的列表视图中使用 dtpicker 过滤日期
- javascript - onclick on image from .setAttribute('onclick', 'imgClick(this)') 如何获取图像索引
- python - Python 新手 - Django manage.py runserver 语法无效
- reactjs - 克服 Axios 请求缓存的策略?