当前位置: 首页 > 知识库问答 >
问题:

加载ApplicationContext期间的Broadleaf JUnit测试错误

程皓轩
2023-03-14

使用Broadleaf 5.2.2-GA版多租户版本

package com.test.simple;

import javax.annotation.Resource;

import org.broadleafcommerce.core.catalog.service.CatalogService;
import org.broadleafcommerce.test.config.BroadleafSiteIntegrationTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@BroadleafSiteIntegrationTest
public class JUnitTest {

    @Resource
    private CatalogService catalogService;

    @Test
    public void testInjectionWorks() {
        Assert.assertNotEquals(catalogService, null);
    }
}
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.broadleafcommerce</groupId>
    <artifactId>integration</artifactId>
    <version>${blc.version}</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.broadleafcommerce</groupId>
    <artifactId>integration</artifactId>
    <version>${blc.version}</version>
    <classifier>tests</classifier>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->
<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <scope>test</scope>
</dependency>

请帮助检查如何解决此错误。

共有1个答案

王季萌
2023-03-14

在我看来,当前错误的原因是该StackTrace的以下摘录:

org.springframework.context.ApplicationContextException: More than one UserDetailsService registered. Please use a specific Id reference in or elements.

您似乎有多个cachinguserdetailsserviceuserdetailsservicebean正在实例化。如果查看UserDetailsServiceFactoryBean#GetUserDetailsService的源代码,您将看到它在哪里验证只有一个。我将研究您的安全配置,并找出为什么要注册多个userdetailsservicebean。

 类似资料: