【发布时间】:2015-03-15 22:39:45
【问题描述】:
我遵循了 Spring 组织为 Spring Data JPA 提供here 的示例。
这是我的存储库界面:
public interface CustomerRepository extends CrudRepository<Customer, Long> {
List<Customer> findByLastName(String lastName);
}
这是我的 Application 类的 sn-p:
@Configuration
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Application.class);
CustomerRepository repository = context.getBean(CustomerRepository.class);
我收到以下错误:
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [hello.CustomerRepository] is defined
我尝试将@Repository 注释添加到CustimerRespository 并将@ComponentScan 注释添加到Application 类,但结果是一样的。
【问题讨论】:
-
Application驻留在哪个包中?CustomerRepository驻留在哪个包中? -
所有类都在同一个包中,名称为“hello”。
-
你有机会分享这个项目吗?
-
是的。这是一个 GitHub 存储库:github.com/oanacioara/SpringJpaExample
-
您是否有特定原因不使用 Spring Boot 来管理您的依赖项?即:使用parent 或"bill of material" using scope import
标签: spring exception repository spring-data spring-data-jpa