使用注解开发



1)bean:

//@Component等价于<context:component-scan base-package="com.kakafa.pojo"/>
@Component
public class User {
    private String name; 
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">

    <!--指定要扫描的包,这个包下面的注解就会生效-->
    <context:component-scan base-package="com.kakafa.pojo"/>

    <context:annotation-config/>

</beans>

2)属性注入注解:


3)衍生注解


4)自动装配注解

上一篇博客:https://www.cnblogs.com/kakafa/p/15770792.html


5)作用域


6)小结

posted @ 2022-01-06 14:46  卡卡发  阅读(36)  评论(0)    收藏  举报