未创建Spring JPA Repository实例

时间:2015-01-17 11:26:49

标签: spring exception repository spring-data spring-data-jpa

我遵循Spring组织为Spring Data JPA提供here的示例。

这是我的存储库界面:

public interface CustomerRepository extends CrudRepository<Customer, Long> {

    List<Customer> findByLastName(String lastName);
}

这是我的Application类的片段:

@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类,但结果是相同的。

1 个答案:

答案 0 :(得分:0)

也许尝试添加配置类

  

@EnableJpaRepositories
  @EnableConfigurationProperties()
  @EntityScan({&#34; com.project.app.entities&#34;})