spring-boot - 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;
}
解决方案
推荐阅读
- pyspark - pyspark - 并行化文件处理的问题
- html - 带有短垂直线的 CSS 样式导航栏
- php - 如何通过 Ajax jQuery 发送多个输入值
- python - 是否可以使 __init__ 文件动态描述父包?
- javascript - 使用jquery的相同嵌套数组数据的总和
- flutter - 如何在自己弹出时导航到命名路线?
- python - 请帮助计算使用 Python 或 Pandas 的设备数量?
- html - npm 包正在创建一个带有已编译 css 的 dist 文件夹,该 css 覆盖了主 css 文件夹
- phpmyadmin - 我正在尝试设置 phpmyadmin 并收到警告。我试图解决这些问题,但对我没有用。谁能帮我?
- reactjs - 通过单击按钮显示来自 firebase 的单个数据信息