Userdaoimpl
Package com.bjsxt.dao.impl;import Com.bjsxt.dao.userdao;import com.bjsxt.model.User; Public classUserdaoimpl implements Userdao {Private intdaoid; Public intgetdaoid () {returndaoid; } Public voidSetdaoid (intdaoid) { This. daoid =daoid; } Public voidSave (User user) {//Hibernate//JDBC//XML//NetWorkSystem. out. println ("User saved!"); } @Override PublicString toString () {return "daoid="+daoid; }}
Beans.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"xsi:schemalocation="Http://www.springframework.org/schema/beanshttp//www.springframework.org/schema/beans/spring-beans-2.5.xsd "> <bean name="Userdao" class="Com.bjsxt.dao.impl.UserDAOImpl"> <property name="daoid"Value="1"></property> </bean> <bean name="userDAO2" class="Com.bjsxt.dao.impl.UserDAOImpl"> <property name="daoid"Value="2"></property> </bean>//default refers to automatic assembly by specifying default on the table header and then setting it to default to be specified by the table header <bean id="UserService" class="Com.bjsxt.service.UserService"Scope="prototype"Autowire="Bytype">//will automatically match according to name Userdao only one property per type can be line </bean> </beans>
Testadd
@Test publicvoid Testadd () throws Exception { new Classpathxmlapplicationcontext ("beans.xml"); = (UserService) ctx.getbean ("userservice"); System. out . println (Service.getuserdao ()); }
Spring re-contact automatic assembly