java中成员变量productDao并没有初始化,为什么可以调用方法?
伊谢尔伦
伊谢尔伦 2017-04-18 10:56:06
0
6
630

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(6)
阿神

Autowired修饰了该变量,Spring容器中获取对应的Bean is set to the value of this variable.

洪涛

You use the Spring framework and annotate the ProductController with @Controller to be managed by Spring. When ProductController is instantiated, it will search for @Autowired and inject other instances managed by Spring.

黄舟

productDao uses the @Autowired annotation, which means that instances are automatically injected from the Spring context.

Classes in the Spring context are all singletons. After startup, these classes will be initialized in the context, so you can call them directly in ProductController.

大家讲道理

This is automatically injected, ProductDaoFacade should be declared as a bean.

ps:ProductDaoFacade这个代码写得真是太奇怪了,明明是个interface还facade(这是一个设计模式)。同时,还放了那么多常量,这是典型的constant interface。简单来说,建议使用枚举类。如果想深入了解一下,建议参考effective java中的建议之一————接口只用于定义类型.

Peter_Zhu

spring found the @Controller annotation during package scanning and managed and maintained the controller class. After discovering @Autowired, it started the assembly mechanism and searched in the context of the beans managed by Spring according to the changed attribute type and injected it. The professional term is called IOC

伊谢尔伦

This framework called Chun has done it for you<_<

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!