[英]Spring bean not identified with @Repository annotation
I have written a sample spring boot application and it is failing to run with message 我已经编写了一个示例spring boot应用程序,它无法通过消息运行
` Description: Field customerRepository in com.hibernatetutorial.service.CustomerServiceImpl required a bean of type 'com.hibernatetutorial.repository.CustomerRepository' that could not be found. `描述:com.hibernatetutorial.service.CustomerServiceImpl中的字段customerRepository需要一个类型为'com.hibernatetutorial.repository.CustomerRepository'的bean。
Action: Consider defining a bean of type 'com.hibernatetutorial.repository.CustomerRepository' in your configuration.` 行动:考虑在您的配置中定义一个类型为“ com.hibernatetutorial.repository.CustomerRepository”的bean。
I have a @Repository annotation on CustomerRepository class and it's package is the there in base package scanning. 我在CustomerRepository类上有一个@Repository批注,它的包位于基本包扫描中。
Below is configuration 下面是配置
@SpringBootApplication
@ComponentScan(basePackages="com.hibernatetutorial")
public class HibernateTutorialApplication {
public static void main(String[] args) {
SpringApplication.run(HibernateTutorialApplication.class, args);
}
}
@Repository
@Transactional
public interface CustomerRepository extends JpaRepository<Customer, UUID>{
}
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
@Autowired
private CustomerRepository customerRepository;
public Customer createCustomer(Customer customer) {
return customerRepository.save(customer);
}
}
Customer entity is annotated with @Entity. 客户实体用@Entity注释。 Any suggestion if I miss anything 如果我错过任何建议
To make use of JpaRepository you need to add one of the following to your Application: 要使用JpaRepository,您需要向应用程序中添加以下内容之一:
@EnableAutoConfiguration
for Spring Boot to figure it out itself or @EnableAutoConfiguration
for Spring Boot可以自行解决或
@EnableJpaRespositories(basePackageScan="com.example")
to specify it yourself @EnableJpaRespositories(basePackageScan="com.example")
指定
请确认您的CustomerRepository和CustomerServiceImpl Java文件在com.hibernatetutorial相同的软件包中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.