假设我有这样的接口:
interface Country {}
class USA implements Country {}
class UK implements Country ()
Run Code Online (Sandbox Code Playgroud)
这个配置xml片段:
<bean class="USA"/>
<bean id="country" class="UK"/>
<bean id="main" class="Main"/>
Run Code Online (Sandbox Code Playgroud)
如何控制下面自动连接的依赖项?我想要英国人.
class Main {
private Country country;
@Autowired
public void setCountry(Country country) {
this.country = country;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用的是Spring 3.0.3.RELEASE.
@Injectand @Resource和@Autowired注释之间有什么区别?
我们什么时候应该使用它们?
请NoSuchBeanDefinitionException在Spring中解释以下关于异常的内容:
本文旨在对NoSuchBeanDefinitionException使用Spring的应用程序中出现的问题进行全面的问答.
我有一个依赖于 Repository Bean 的服务类
@Service
public class SomeService{
private Repo repoClass;
@Autowired
public SomeService(Repo repoClass){
this.repoClass = repoClass;
}
//Methods
}
Run Code Online (Sandbox Code Playgroud)
但是我有两种回购
public class JdbcRepo implements Repo{
}
public class HibernateRepo implements Repo {
}
Run Code Online (Sandbox Code Playgroud)
我如何制作两个豆子,SomeService其中一个注入了JdbcRepo另一个注入了HibernateRepo?