ioc控制反转:
-
@Component:相当于<bean></bean>
-
@Repository:专门处理dao层,交给ioc容器
-
@Service:专门处理service层,交给ioc容器
-
@Controller:专门处理web层,交给ioc容器
依赖注入:
-
@Autowired:相当于 <property></property> ,根据类型注入
-
@Qualifies:与@Autowired一起使用,根据id查找同类型下的实例
-
@Resource :jdk提供的注解(@Autowired+@Qualifies)
-
@Scope:相当于 <bean scope=""></bean>
singleton:单例对象(默认)
prototype:多例对象 -
@PostConstruct:相当于 <bean init-method=""></bean>
-
@PreDestroy:相当于 <bean detroy-method=""></bean>
-
@Value:通过${} SPEL,从配置文件中获取数据
-
@Configuration : 相当于applicationContext.xml
-
@Bean:加载第三方类(对象),交给ioc容器
-
@PropertySource :相当于 <context:property-placeholder location=""/> 读取配置文件
-
@ComponentScan :相当于 <context:component-scan base-package=""/> 扫描类/包
-
@Import :相当于
把字段转换成字符串
- @JsonSerialize(using = ToStringSerializer.class)
多例
- @Scope(“prototype”):把注解打在类上,则每次注入都会相当于new 一个新的类