Spring re-contact automatic assembly

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.