Spring @JdbcTest 尝试创建其他 bean

问题描述

我尝试测试我的存储库类,但是当我尝试测试它时,我遇到了应用程序失败异常。

网络应用程序:

@SpringBootApplication
@ComponentScan("co.mainpackage")
public class WebApplicationConfig
{
   ...
       @Bean
    public StringRedistemplate redistemplate(LettuceConnectionFactory redisConnectionFactory)
    {
        StringRedistemplate template = new StringRedistemplate();
        template.setConnectionFactory(redisConnectionFactory);
        template.setValueSerializer(new StringRedisSerializer());
        return template;
    }
}

关键字存储库:

@Repository
@Transactional
public class KeywordRepository
{
  private final NamedParameterJdbcTemplate jdbcTemplate;
  ...
}

KeywordRepositoryTest:

@JdbcTest
@Import({KeywordRepository.class})
@AutoConfigureTestDatabase( replace = AutoConfigureTestDatabase.Replace.NONE)
@sql("/data/keyword.sql")
public class KeywordRepositoryTest
{
    @Autowired
    private KeywordRepository keywordRepository;
    ...
}

错误提示

java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'otherBean'
...

在这里,我应该使用 @ComponentScan 因为我有多模块项目... 我需要 @AutoConfigureTestDatabase,因为我使用嵌入式测试数据库

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)