【问题标题】:cucumber test, jhipster and oauth: ClientRegistrationRepository bean not found黄瓜测试,jhipster 和 oauth:找不到 ClientRegistrationRepository bean
【发布时间】:2021-01-10 09:26:45
【问题描述】:

当我将其配置为使用 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-security oauth cucumber jhipster spring-security-oauth2


    【解决方案1】:

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

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

    我们必须把它改成:

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

    【讨论】:

      猜你喜欢
      • 2021-02-19
      • 2016-06-25
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多