小伙看你根骨奇佳,潛力無限,來學(xué)PHP伐。
Autowired
修飾了該變量,Spring
容器中獲取對應(yīng)的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(這是一個設(shè)計模式)。同時,還放了那么多常量,這是典型的constant interface
。簡單來說,建議使用枚舉類。如果想深入了解一下,建議參考effective java中的建議之一————接口只用于定義類型
.
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