简体   繁体   English

Spring中的bean实例化和依赖注入

[英]bean instantiation and dependency injection in Spring

I'm new to Spring and I'm trying to understand what happens during runtime. 我是Spring的新手,我想了解运行时会发生什么。 I know that using dependency injection (for example the Setter injection) in Spring enables the Spring container to create these beans or set values to the beans. 我知道在Spring中使用依赖项注入(例如Setter注入)可以使Spring容器创建这些bean或为bean设置值。

However, is this bean creation occurring at runtime or at compile time? 但是,这种bean创建是在运行时还是在编译时进行的? If you could give me a link that explains this step by step it'll be really helpful too. 如果您可以给我一个逐步说明此问题的链接,那也将非常有帮助。

All bean creation and injection happens at runtime. 所有bean的创建和注入都在运行时进行。 Spring uses reflection to find types and their methods to do this. Spring使用反射来查找类型及其方法。

It's explained in detail in the documentation . 文档中对其进行了详细说明 See chapter 5 on the Inversion of Control Container. 请参阅第5章“控制容器反转”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM