您的位置:首页 > 编程语言 > Java开发

关于spring的注入类型

2014-06-21 11:24 211 查看
 关于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)接口注入(不推荐使用)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: