2 beans with the same name but with a different package like autwire?
In my java project I have two objects with the same name but with a different package, also I have a corresponding dao for these objects.
Now, due to two entities with the same name, it was throwing a duplicate scan error, so I added a name attribute to those entities with their fully qualified names.
Ex: Entity (name = "pckEntity) and Entity (name =" pabEntity)
But now I their respective daos cannot autwire and I get the following error:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type...
I need to change something in Dao to support this change to the "name" attribute in the entity.
I am using Hibernate, JPA and Spring.
source to share
By default, autoinstall is performed by type. This way you can use the annotation directly @Autowired
, since both objects are different classes, make sure they are spring beans (here I mean they are managed by Spring).
@Autowired // nothing to specify, Spring automatically autowire the bean by checking type
private p.c.k.Entity entity;
@Autowired // nothing to specify, Spring automatically autowire the bean by checking type
private p.a.b.Entity entity1;
source to share