Spring re-contact set injection

Source: Internet
Author: User

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="sets"> <Set> <value>1</value> <value>2</value> </Set> </property> <property name="lists"> <list> <value>1</value> <value>2</value> <value>3</value> </list> </property> <property name="Maps"> <map> <entry key="1"Value="1"></entry> <entry key="2"Value="2"></entry> <entry key="3"Value="3"></entry> <entry key="4"Value="4"></entry> </map> </property> </bean> <bean id="UserService" class="Com.bjsxt.service.UserService"> <!--<property name="Userdao"> <refbean="Userdao"/> </property> <constructor-arg> <refbean="Userdao"/> </constructor-arg> </bean></beans>

Userdaoimpl

Package Com.bjsxt.dao.impl;import Java.util.list;import java.util.map;import java.util.set;import Com.bjsxt.dao.userdao;import Com.bjsxt.model.User; Public classUserdaoimpl implements Userdao {/*(non-javadoc) * @see com.bjsxt.dao.userdao#save (com.bjsxt.model.User)*/    PrivateSet<string>sets; PrivateList<string>lists; PrivateMap<string, string>maps;  PublicSet<string>getsets () {returnsets; }     Public voidSetsets (set<string>sets) {         This. Sets =sets; }     PublicList<string>getlists () {returnlists; }     Public voidSetlists (list<string>lists) {         This. Lists =lists; }     PublicMap<string, string>getmaps () {returnmaps; }     Public voidSetmaps (map<string, string>maps) {         This. maps =maps; }     PublicUserdaoimpl () {} Public voidSave (User user) {System. out. println ("User saved!"); } @Override PublicString toString () {return "Sets Size:"+ sets.size () +"| Lists size:"+ lists.size () +"| maps Size:"+maps.size (); }}

Test

@Test      Public void Testadd () throws Exception {        new classpathxmlapplicationcontext ("beans.xml " );         = (Userdao) ctx.getbean ("userdao");        System.  out . println (U1);    }

Spring re-contact set injection

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.