首页 > 解决方案 > BeanCreationException:创建名为“Reposit”的 bean 时出错:调用 init 方法失败

问题描述

尝试启动应用程序时出现以下错误。我尝试了多重解决方案,但似乎没有一个有效。

*引起:org.springframework.beans.factory.BeanCreationException:创建名为“testRepository”的bean时出错:调用init方法失败;嵌套异常是 java.lang.IllegalArgumentException: 无法为方法 public abstract java.util.List com.test.base.repository.TestRespositoryCustom.findResultByCodeAndProfile(java.lang.String,java.lang.String) 创建查询!找不到类型 Test 的属性 findResultByCodeAndProfile!

...................................

............ 47个常见框架省略 原因:org.springframework.data.mapping.PropertyReferenceException:没有找到类型Test的属性findResultByCodeAndProfile!在 org.springframework.data.mapping.PropertyPath.(PropertyPath.java:94) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE] 在 org.springframework.data.mapping.PropertyPath .create(PropertyPath.java:382) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]*

我的服务类正在调用调用接口 TestRespositoryCustom 的 findResultByCodeAndProfile 方法,该方法的实现在 TestRespositoryImpl 类的下面。

“Test.java 是实体类”

——服务等级。

@Autowired
TestRepository testRepository;

     public void getHotelProfileLatestTest(String hotelCode)
    {
        List<TestDto> testList = testRepository.findResultByCodeAndProfile(secondaryCode, "profile");
        //
        //
    }

--TestRepository 接口

public interface TestRepository extends BaseRepository<Test, Long>, TestRepositoryCustom {

    {
    @Query(TestQueries.NOTE_QRY)
    Page<TestDto> getHistory(@Param("Key") String Key,
            @Param("Value") String Value);
    }

-- BaseRepository 接口。

        @NoRepositoryBean
    public interface BaseRepository <T, ID extends Serializable> extends JpaRepository<T, ID>, QueryByExampleExecutor<T>{

}

--TestRespositoryCustom

public interface TestRespositoryCustom
{
    public List<TestDto> findResultByCodeAndProfile(String testObjKey, String testObjValue);
}

--TestRespositoryImpl

public class TestRespositoryImpl extends BaseRepositoryCustom implements TestRespositoryCustom
{
   @Override
    public List<TestDto> findResultByCodeAndProfile(String testObjKey, String testObjValue)
    {
        String sql = TC_NOTE_QRY;
        Query query = entityManager.createQuery(sql);
        query.setMaxResults(3);
        query.setParameter("testObjKey", testObjKey);
        query.setParameter("testObjValue", testObjValue);
        return (List) query.getResultList();
    }

-- BaseRepositoryCustom

public class BaseRepositoryCustom {

    @Value("${spring.jpa.properties.hibernate.default_schema}")
    public String defaultSchema;

    @PersistenceContext
    protected EntityManager entityManager;

}

标签: spring-bootjpaspring-data-jpabeancreationexception

解决方案


推荐阅读