依赖注入:
当使用 注解时:
在功能类上 加注解 @Service
在使用功能类的bean上 加注解
@Service 加在类名上
@Autowired 加在 实例化对象上 表示注入到IOC容器中
@ComponentScan 自动扫描 注解类 注册为bean
最后在 annotationConfigApplicationContext 里加载 被@ComponentScan修饰的类
本文深入探讨了依赖注入的概念,介绍了如何通过@Service和@Autowired注解实现类的实例化和注入,以及如何利用@ComponentScan进行类的自动扫描与注册。
依赖注入:
当使用 注解时:
在功能类上 加注解 @Service
在使用功能类的bean上 加注解
@Service 加在类名上
@Autowired 加在 实例化对象上 表示注入到IOC容器中
@ComponentScan 自动扫描 注解类 注册为bean
最后在 annotationConfigApplicationContext 里加载 被@ComponentScan修饰的类

被折叠的 条评论
为什么被折叠?