search

Home  >  Q&A  >  body text

java中成员变量productDao并没有初始化,为什么可以调用方法?

伊谢尔伦伊谢尔伦2805 days ago667

reply all(6)I'll reply

  • 阿神

    阿神2017-04-18 10:58:06

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 10:58:06

    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.

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:58:06

    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.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:58:06

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

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

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 10:58:06

    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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:58:06

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

    reply
    0
  • Cancelreply