spring注解注入的学习

spring在开发中起到管理bean的作用,不管是web应用还是应用软件开发。
注入有多种方式,其中注解注入最为受欢迎。(java api 在1.6版本以上才引入关键的注解类如:@Resource)

配置文件xml

<?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
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">
   <context:annotation-config/>
   
   <bean id="person" class="com.test.spring.bean.person">
       <property name="name" value="xxx"/>
       <property name="sex" value="男"/>
       <property name="addr" value="广州"/>
   </bean>
   <bean id="jianli" class="com.test.spring.bean.jianli">
       <property name="wenping" value="博士"/>
   </bean>
</beans>

注意红色部分配置,缺一都用不了注解注入

原文地址:https://www.cnblogs.com/wbjgogogo/p/5142472.html