我使用带有弹簧数据jpa的spring boot 2应用程序和带有postgres的hibernate
package com.acmor.togy.repository.util.postgres
@Component
public class HStoreParameter implements FormatParameter{
...
}
package com.acmor.togy.repository.util;
public interface FormatParameter {
String format(Map<String, String> properties);
}
package com.acmor.togy.repository.util;
public class AbstractRepository<T, ID> extends SimpleJpaRepository<T, ID> {
private ThreadLocal<Map<String, Object>> parameters = new ThreadLocal<>();
@Autowired
private FormatParameter formatParameter;
public AbstractRepository(JpaEntityInformation entityInformation, EntityManager entityManager) {
super(entityInformation, entityManager);
}
public AbstractRepository(Class domainClass, EntityManager em) {
super(domainClass, em);
}
}
package com.acmor.togy.repository;
@Repository
public class EnumsRepositoryImpl extends AbstractRepository implements EnumsRepositoryCustom {
}
public interface EnumsRepositoryCustom {
...
}
我创建了一个基本测试
@RunWith(SpringRunner.class)
public class EnumsRepositoryCustomTest {
@Autowired
private EnumsRepositoryCustom enumsRepository;
@Test
public void test_advanced_search_using_properties() {
EnumsSearch search = new EnumsSearch();
...
Page<Enums> page = enumsRepository.search(search, PageRequest.of(0, 10));
...
}
}
当我进行测试时,我得到了
引起: org.springframework.beans.factory.NoSuchBeanDefinitionException:没有 合格的bean类型 'com.acmor.togy.repository.util.FormatParameter'可用:预期 至少有1个符合autowire候选资格的bean。依赖 注释: {@ org.springframework.beans.factory.annotation.Autowired(所需=真)}
我有一个FormatParameter的实现,它是HStoreParameter