Can we use @autowired on an entity object in spring?

后端 未结 4 1026
别跟我提以往
别跟我提以往 2021-01-22 01:18

I have a entity class called Customer, I am using this entity object in another class to set the data. When I use this object below like

@Autowired
         


        
4条回答
  •  梦谈多话
    2021-01-22 01:44

    In fact, Spring support @Autowire only for Spring Beans. A java class becomes Spring Bean only when it is created by Spring, otherwise it is not.

    A workaround might be to annotate your class with @Configurable but you would have to use AspectJ

    Please look in the Spring documentations on how to use @Configurable

    Also, I wonder why you would autowire an entity class ?

提交回复
热议问题