简体   繁体   English

即使我已经在我的 ServiceImpl class 中自动装配实体,它仍然给我与自动装配相关的错误

[英]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.

相关问题 在服务层 class 中找不到 RestTemplate bean,即使我已经自动装配了它 - RestTemplate bean is not found in the service layer class even though i have autowired it 错误告诉我运行类中的方法未定义,即使它是 - Error telling me that the method in my run class is undefined even though it is Java一直给我一个错误,即使没有红线 - Java keeps giving me an error even though there is not red line thingy 即使在另一个控制器中实例化,Autowired属性也会给出null - Autowired property giving null even though it instantiates in another controller 无法使用服务类对象自动装配ServiceImpl类Bean - Unable to Autowire ServiceImpl Class Bean with Service Class Object 即使我在清单文件中定义了Main-class,也会出现“错误:找不到或加载类” - Getting “Error: Could not find or load class” even though I have the Main-class defined in a Manifest File 春天不允许我自动上课 - Spring not allowing me to autowire my class 为什么我的构造函数未定义,即使我在另一个 class 中创建了构造函数? - Why is my constructor is undefined even though I have made a constructor in another class? 我想将我的TicTacToe类中的点返回到主类中,但是它一直给我这个错误? - I want to return the points from my TicTacToe class to my main class but it keeps giving me this error? 即使我的 for 循环中有一个 return 语句,为什么我会因为没有 return 语句而收到错误消息? - Why do I get an error for not having a return statement even though I have one in my for loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM