关于spring的注入类型

来源:互联网 发布:郭靖对杨过的影响知乎 编辑:程序博客网 时间:2024/04/29 21:23

 关于spring的注入类型有三种:

         a)setter,(重要的)

<?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"       xmlns:aop="http://www.springframework.org/schema/aop"       xsi:schemaLocation="http://www.springframework.org/schema/beans            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd           http://www.springframework.org/schema/context           http://www.springframework.org/schema/context/spring-context-3.1.xsd           http://www.springframework.org/schema/aop           http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">     <bean id="serviceLogging" class="com.pb.aop.ServiceLogging"></bean>     <bean id="userService" class="com.pb.service.UserService"></bean>        </beans>


         b)构造方法(可以忘记,但是有印象)

                       若构造方法中有多个参数,需要用索引进行标记注入或者类型进行标记注入。

                 

<constructor-arg index="0" value="7500"></constructor-arg><constructor-arg index="1" value="75"></constructor-arg>


         c)接口注入(不推荐使用)

0 0