首页 > 解决方案 > 黄瓜测试,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.

我该如何解决这个问题?

标签: spring-securityoauthcucumberjhipsterspring-security-oauth2

解决方案


解决方法是找到CucumberContextConfiguration类。它包含这样的注释:

@ContextConfiguration(classes = [HelloworldApp::class])

我们必须将其更改为:

import com.example.helloworld.config.TestSecurityConfiguration
(...)
@ContextConfiguration(classes = [HelloworldApp::class, TestSecurityConfiguration::class])

推荐阅读