[英]Even though I have autowired the entity in my ServiceImpl class, its still giving me the error related to autowire
This is my Impl Class这是我的 Impl Class
@Service
public class TransactionServiceImpl implements TransactionService{
@Autowired
private Customer customer;
This is the error I am getting这是我得到的错误
Field customer in com.rewardsystem.AugustStore.service.TransactionServiceImpl required a bean of type 'com.rewardsystem.AugustStore.entities.Customer' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.rewardsystem.AugustStore.entities.Customer' in your configuration.
I tried to redo the steps but the problem still arises我尝试重做这些步骤,但问题仍然存在
I can see that you are trying to autowire Customer
class that is Entity class (as per error message) and Entity classes are not beans (annotated with @Service , @Component , @Configuration , @Repository and @Bean ).我可以看到您正在尝试自动装配
Customer
class 即实体 class(根据错误消息)并且实体类不是 beans(用@Service 、 @Component 、 @Configuration 、 @Repository和@Bean 注释)。 So you can't use them as a dependency in other classes by using @Autowired annotation.因此,您不能通过使用@Autowired注释将它们用作其他类中的依赖项。
So please remove @Autowired annotation on top Customer
class and create instance using new operator like this因此,请删除顶部
Customer
class 上的@Autowired注释,并使用这样的新运算符创建实例
Customer customer=new Customer();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.