2013-01-24 66 views
3

在我的java项目中,我有两个具有相同名称但不同包的实体,我也有相应的这些实体的道。2个具有相同名称但不同包的bean,如何自动装配?

现在由于具有相同名称的2个实体,它给出了重复的扫描错误,因此我使用完全限定名称向这些实体添加了名称属性。

例:实体(NAME = “pckEntity)&实体(NAME =” pabEntity)

但现在我自己相应的daos不能自动装配,和我收到以下错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type... 

我是否还必须更改Dao中的任何内容以支持实体中的“名称”属性更改。

我正在使用Hibernate,JPA和Spring。

+0

请包括完整的堆栈跟踪和代码片段,显示您当前如何自动连接DAO的 –

回答

0

我想你可以使用@Qualifier注释

@Autowired 
@Qualifier("p.c.k.Entity") 
private Entity entity; 

接到here

0

默认情况下自动连接是通过类型来完成的。所以你可以直接使用@Autowired注解,因为两个实体都是不同的类,确保那些是spring bean(这里我指的是那些由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; 
0

我也有这个问题,并找不到任何方法来解决它,而不是重命名其中一个类。在不同的包装中应该够了,但事实并非如此。

相关问题