[英]Spring Bean and Autowire to datasource
Noob to Spring. 从菜鸟到春天。 I have 2 files: foo-servlet.xml which has the following statement:
我有2个文件:foo-servlet.xml,其中包含以下语句:
<bean id:"DAO" class="a.b.data.MyDAO"/>
fooController.java has the following: fooController.java具有以下内容:
@Controller
public class FooController{
@Autowired
private FooDAO fooDAO;
public void setFooDAO (FooDAO fooDAO){ this.fooDAO = fooDAO;}
My question: Is Spring actually replacing / injecting the definition of DAO in the servlet into my FooDAO? 我的问题:Spring是否真的将Servlet中DAO的定义替换/注入了我的FooDAO中? I'm trying to understand the 'tie-in' between the bean and how Spring know to substitute that file for my FooDAO in the controller.
我试图理解Bean之间的“联系”,以及Spring如何知道用该文件替换控制器中的FooDAO。
Oh, and there is no mention of @Repository or @Component anywhere in this example code... 哦,在此示例代码中的任何地方都没有提到@Repository或@Component。
The XML looks kind of corrupted. XML看起来有点损坏。 I think it needs to be id=DAO As far as i know: Autowiring is either done via the type or the name and the type.
我认为它应该是id = DAO据我所知:自动装配是通过类型或名称和类型完成的。 So when MyDAO implements FooDao your bean will be considered for Autowiring.
因此,当MyDAO实现FooDao时,将考虑将您的bean进行自动装配。 But this is just a guess.
但这只是一个猜测。 The code of the Daos and the rest of the configuration would be helpful to give a correct answer to this question.
Daos和其余配置的代码将有助于正确回答此问题。 Understanding Spring @Autowired usage This might answer your question as well.
了解Spring @Autowired用法这也可能会回答您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.