Spring 容器中使用注解实例化类
使用注解 ' @Component ' 或其衍生注解(如 ' @Service '、' @Controller '、' @Repository ' 等)将类标记为一个 bean,并使用注解 ' @Autowired ' 或 ' @Resource ' 将该 bean 注入到其他类中,即可将类实例化至 Spring 容器。同时,需要在配置文件中开启组件扫描,让 Spring 自动扫描并实例化被标记为 bean 的类。
原文地址: https://www.cveoy.top/t/topic/kdj5 著作权归作者所有。请勿转载和采集!