Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
708 views
in Technique[技术] by (71.8m points)

Spring boot 2.3.x + Zalando Problem + Testing

I have a spring boot 2.3.8 app working well. I used Zalando Problem object in it. Now I want to write Repository test for this app, and I've got a weird error message:

UnsatisfiedDependencyException: Error creating bean with name    
'org.zalando.problem.spring.web.advice.security.SecurityProblemSupport': Unsatisfied 
dependency expressed through constructor parameter 0; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 
'org.springframework.web.servlet.HandlerExceptionResolver' available: expected at least 1 
bean which qualifies as autowire candidate. Dependency annotations: 
{@org.springframework.beans.factory.annotation.Qualifier("handlerExceptionResolver")}

My test code is like this:

@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Testcontainers
class RepositoriesTest @Autowired constructor(
                     val siteRepository: SiteRepository,
                     val horseRepository: HorseRepository,
                     val sensorRepository: SensorRepository,
                     val boxRepository: BoxRepository){

companion object {
    @Container
    private val postgreSQLContainer = PostgreSQLContainer<Nothing>("postgres:latest")

    @DynamicPropertySource
    @JvmStatic
    fun registerDynamicProperties(registry: DynamicPropertyRegistry) {
        registry.add("spring.datasource.url", postgreSQLContainer::getJdbcUrl)
        registry.add("spring.datasource.username", postgreSQLContainer::getUsername)
        registry.add("spring.datasource.password", postgreSQLContainer::getPassword)
    }
}

val plszName="plsz"

    @Test
    fun `repoTests` () {
        val plsz=siteRepository.findByUrlParam(plszName)
        Assertions.assertThat(plsz).isNotNull
    }
 }

Do I need to configure zalando problem module in test environment? And how? thx, Zamek

question from:https://stackoverflow.com/questions/65891126/spring-boot-2-3-x-zalando-problem-testing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...