我有一个应用程序'app_test',它包含一个具有@Service注释的类TestClass。我有一个类库'lib_test',其中包含id为'TestClass'的XML文件中的bean。两者都有不同的包装。注入2个具有相同类名的bean
我米注入@Service豆如下
Import com.app.TestClass
Class TestController
{
Private final TestClass testClass;
@Inject
TestController (TestClass testClass)
{
This.testClass =testClass;
}
}
应该由类型,因为它们是在不同的包中注入。但是控制器正在给出未找到的合格bean。
我可以通过给予@Qualifier和给@Service命名来解决它。但是,它需要吗?由于两者都在不同的包装中,它应该通过类型自动装配?或者m错过了一些概念?
可能的重复:http://stackoverflow.com/questions/3925681/spring-autowired-with-2-beans-of-the-same-type – pringi
不是。它是一个具有相同的包和不同的名称。 M谈论不同的包和同名。 –