Spring 4 依赖注入
来源:互联网 发布:空号检测软件 编辑:程序博客网 时间:2024/06/03 06:04
对于bean的属性 进行注入
3.工厂注入,有静态和非静态,非静态bean写一个factory-bean 静态直接调用方法(非静态不写)
感觉还是第一个参数注入舒服点
4.内部bean,list,map使用,主要要new map()
1.参数注入
<bean id="user" class="com.cai.helloworld.User"> <property name="id" value="1" ></property> <property name="username" value="cai"></property> <property name="password" value="123"></property> <property name="age" value="12"></property> </bean>2.构造方法注入 可以是name也可以是index
<bean id="user" class="com.cai.helloworld.User"> <constructor-arg name="id" value="1" ></constructor-arg> <constructor-arg name="username" value="cai"></constructor-arg> <constructor-arg name="age" value="12"></constructor-arg> <constructor-arg name="password" value="123"></constructor-arg> </bean>
3.工厂注入,有静态和非静态,非静态bean写一个factory-bean 静态直接调用方法(非静态不写)
<bean id="user" class="com.cai.helloworld.CreatUser" factory-method="creatUser"></bean>
public class CreatUser { public static User creatUser(){ User user=new User(); user.setId(1); user.setAge("12"); user.setPassword("123"); user.setUsername("cai"); return user; }}
感觉还是第一个参数注入舒服点
4.内部bean,list,map使用,主要要new map()
<bean name="dog" class="com.cai.helloworld.Dog"></bean> <bean id="user" class="com.cai.helloworld.User"> <property name="id" value="1" ></property> <property name="username" value="cai"></property> <property name="password" value="123"></property> <property name="age" value="12"></property> / <!-- 引用<property name="dog" ref="dog" >--> <!-- 内部bean --> <property name="dog" > <bean class="com.cai.helloworld.Dog"> <property name="name" value="tom"></property> <property name="age" value="1"></property> </bean> </property> <property name="hobbys" > <list> <value>唱歌</value> <value>跳舞</value> </list> </property> <property name="nameandage" > <map> <entry> <key><value>上午</value></key> <value>1</value> </entry> </map> </property> </bean>
public class User { private int id; private String username; private String password; private String age; private Dog dog=new Dog(); private java.util.List<String> hobbys=new ArrayList<String>(); private Map<String ,Integer > nameandage=new HashMap<String,Integer>();
阅读全文
0 0
- Spring 4 依赖注入
- Spring依赖注入:注解注入
- spring学习笔记(4)依赖注入详解
- spring 的依赖注入
- Spring依赖注入实践经验
- Spring的依赖注入
- Spring依赖注入
- spring(依赖注入-DI)
- spring依赖注入
- spring依赖注入
- 白话spring依赖注入
- Spring依赖注入方式
- Spring的依赖注入
- Spring依赖注入
- Spring依赖注入方式
- Spring 依赖注入
- spring依赖注入方式
- spring的依赖注入
- 《leetCode》:Pow(x, n)
- 51nod 1087 前缀和 STL lower_bound
- HDU 6105 Gameia(思维博弈)
- 2017.8.11个人感悟
- read系统调用剖析
- Spring 4 依赖注入
- Ananagrams
- SpringBoot_Junit
- JVM结构及GC工作机制
- springmvc的controllerAPP接口JSON返回值乱码问题(get方法)
- 一步一步学Vue(五)
- 【暑期多校联萌
- 数学模型--现代优化算法(启发式算法)
- 状压DP——2800 送外卖