我遵循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
类,但结果是相同的。
答案 0 :(得分:0)
也许尝试添加配置类
@EnableJpaRepositories
@EnableConfigurationProperties()
@EntityScan({&#34; com.project.app.entities&#34;})