使用注解@Component或其衍生注解(如@Service、@Controller、@Repository等)将类标记为一个bean,并使用注解@Autowired或@Resource将该bean注入到其他类中。同时,需要在配置文件中开启组件扫描,让Spring自动扫描并实例化被标记为bean的类。


原文地址: http://www.cveoy.top/t/topic/cN6a 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录