如何开启基于注解的自动装配?

答案解析

在配置类或 XML 中添加 @ComponentScan 注解,并确保类上有 @Component、@Service、@Repository、@Controller 等注解。还需开启 @Autowired 支持(@EnableAutowired)。