Spring 使用Crudepositoy从DAO中获取NullPointerException
我使用crudepository获得了java.lang.NullPointerException 我的项目如下所示: strut2作用 服务 存储库 领域Spring 使用Crudepositoy从DAO中获取NullPointerException,spring,spring-data,spring-data-jpa,Spring,Spring Data,Spring Data Jpa,我使用crudepository获得了java.lang.NullPointerException 我的项目如下所示: strut2作用 服务 存储库 领域 class Action { @Autowired MyService service; public String execute(){ service.getList(); return "ok"; } } interface Service { List getList(); } @org.spr
class Action {
@Autowired MyService service;
public String execute(){
service.getList();
return "ok";
}
}
interface Service {
List getList();
}
@org.springframework.stereotype.Service
class ServiceImpl implements Service {
@Autowired MyRepository repo;
List getList(){
return (List)repo.findAll();
}
}
package com.mycompany.repositories;
interface MyRepository extends CrudRepository<MyPojo, String>{}
我也试着自己调试它。我在ServiceImpl类中发现,@Autowired MyRepository为空 看来我找到了答案,谢谢@MartenDeinum from 以下是技巧:
<context:component-scan base-package="com.myproject" />
基本上我也需要
<jpa:repositories base-package="com.myproject.repository" />
寻找积垢希望这能帮助其他人。看来我找到了答案,谢谢@MartenDeinum from 以下是技巧:
<context:component-scan base-package="com.myproject" />
基本上我也需要
<jpa:repositories base-package="com.myproject.repository" />
寻找积垢希望这能帮助其他人。哪个类实现了MyRepository?您能在这里显示定义吗?@SunilChavan我不必实现MyRepository,Crudepository提供了操作我的POJO的功能您介意添加确切的堆栈跟踪吗?顺便说一句,
PersistenceAnnotationBeanPostProcessor
的声明实际上是不必要的。@OliverGeerke嗨,Oliver,谢谢你的评论,堆栈跟踪实际上只告诉我NullPointerException。很高兴在这里看到您^^哪个类实现了MyRepository?您能在这里显示定义吗?@SunilChavan我不必实现MyRepository,Crudepository提供了操作我的POJO的功能您介意添加确切的堆栈跟踪吗?顺便说一句,PersistenceAnnotationBeanPostProcessor
的声明实际上是不必要的。@OliverGeerke嗨,Oliver,谢谢你的评论,堆栈跟踪实际上只告诉我NullPointerException。很高兴在这里见到你^^