我在用
<context:component-scan base-package="com.package.dao"/> (Spring 3)
并在我的 Controller 中使用 @Autowired 将自动检索我需要的 DAO。那是完美的并且有效。
问题是当我需要多个 DAO 管理器时。
我能怎么做?
我试过 @限定符但我不确定道经理的名字。类名不起作用
有人可以帮助我吗?
谢谢!
最佳答案
@Autowired is fundamentally about type-driven injection with optional semantic qualifiers. This means that qualifier values, even when using the bean name fallback, always have narrowing semantics within the set of type matches; they do not semantically express a reference to a unique bean id
...
If you intend to express annotation-driven injection by name, do not primarily use @Autowired - even if is technically capable of referring to a bean name through @Qualifier values. Instead, prefer the JSR-250 @Resource annotation which is semantically defined to identify a specific target component by its unique name, with the declared type being irrelevant for the matching process.
改用@Resource,见here .
关于spring - 自动连线……不止一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6091474/