可以混合用.文档有说明: Spring can accommodate both styles and even mix them together. 混合用的话,有个先后顺序,xml配置会覆盖annotation.原文: Annotation injection is performed before XML injection, thus the latter configuration will override the former for properties wired throug
随着越来越多地使用Springboot敏捷开发,更多地使用注解配置Spring,而不是Spring的applicationContext.xml文件. Configuration注解: Spring解析为配置类,相当于spring配置文件 Bean注解:容器注册Bean组件,默认id为方法名 @Configuration public class AppConfig { @Bean public MyService myService() { return new MyServiceImpl()
一.通用注解 1.项目结构: 2.新建Person类,注解@Component未指明id,则后期使用spring获取实例对象时使用默认id="person"方式获取或使用类方式获取 package hjp.spring.annotation.commen; import org.springframework.stereotype.Component; //@Component @Component("personId") public class Person {