Sad*_*tun 2 java spring crud autowired spring-data-jpa
我已经扩展CrudRepository<ClassName, Id>
了用户定义的接口,但是在尝试使用注入时,@Autowired
我收到以下错误:
创建名称为“helloController”的 bean:通过字段“danCorePrivateRepository”表达的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有“com.sgcorp.repository.DanCorePrivateRepository”类型的合格 bean 可用:预计至少有 1 个有资格作为自动装配候选者的 bean。
HelloController.java
@RestController
@RequestMapping("/hello")
public class HelloController {
@Autowired
private DanCorePrivateRepository danCorePrivateRepository;
@RequestMapping(value = "/service", method= RequestMethod.GET)
public String selectService(){
String result = "<html>";
result += "<div>"+danCorePrivateRepository.findAll()+"</div>";
return result+ "</html>";
}
}
Run Code Online (Sandbox Code Playgroud)
DanCorePrivateRepository.java(用户定义接口)
public interface DanCorePrivateRepository extends CrudRepository<DanaModel, String> {
}
Run Code Online (Sandbox Code Playgroud)
请建议为什么它不正确@Autowired?
注意:在其他一些项目中它正在运行。
请在配置类顶部添加 @EnableJpaRepositories 注释。这个@EnableJpaRepositories注解具有basePackages或basePackageClasses属性,通过它们可以指定Spring Data JPA要扫描的包(使用@Repository注解的包)。
归档时间: |
|
查看次数: |
6002 次 |
最近记录: |