转自:http://blog.csdn.net/longyuan20102011/article/details/7596458
cn.dao
[java] view plain
copy
package cn.dao;
public interface PersonDao {
public abstract void add();
}
cn.dao.imp
[java] view plain
copy
package cn.dao;
public interface PersonDao {
public abstract void add();
}
cn.service
[java] view plain
copy
package cn.service;
public interface PersonService {
public abstract void save();
}
cn.service.imp
[java] view plain
copy
package cn.service.imp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor;
import cn.service.PersonService;
public class PersonServiceBean implements PersonService {
private Set<String> sets=new HashSet<String>();
private List<String> lists=new ArrayList<String>();
private Properties properties=new Properties();
private Map<String, String> maps=new HashMap<String, String>();
public Map<String, String> getMaps() {
return maps;
}
public void setMaps(Map<String, String> maps) {
this.maps = maps;
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
public List<String> getLists() {
return lists;
}
public void setLists(List<String> lists) {
this.lists = lists;
}
public Set<String> getSets() {
return sets;
}
public void setSets(Set<String> sets) {
this.sets = sets;
}
public void save()
{
System.out.println("执行save()方法");
}
}
junit.test
[java] view plain
copy
package junit.test;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import cn.service.imp.PersonServiceBean;
public class SpringTest
{
@Test
public void instanceSpring()
{
AbstractApplicationContext ctx=new ClassPathXmlApplicationContext(new String[]{"beans.xml"});
PersonServiceBean personServiceBean=(PersonServiceBean) ctx.getBean("personService");
System.out.println("-------------set--------------");
for(String value:personServiceBean.getSets())
{
System.out.println(value);
}
System.out.println("-------------list--------------");
for(String value:personServiceBean.getLists())
{
System.out.println(value);
}
System.out.println("-------------properties--------------");
for(Object key:personServiceBean.getProperties().keySet())
{
System.out.println(key+"="+(String)personServiceBean.getProperties().getProperty((String)key));
}
System.out.println("-------------map--------------");
for(String key:personServiceBean.getMaps().keySet())
{
System.out.println(key+"="+(String)personServiceBean.getMaps().get(key));
}
ctx.close();
}
}
beans.xml
[html] view plain
copy
<?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/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="personService" class="cn.service.imp.PersonServiceBean">
<property name="sets">
<set>
<value>第一个set</value>
<value>第二个set</value>
<value>第三个set</value>
</set>
</property>
<property name="lists">
<list>
<value>第一个list</value>
<value>第二个list</value>
<value>第三个list</value>
</list>
</property>
<property name="properties">
<props>
<prop key="key1">value1</prop>
<prop key="key2">value2</prop>
<prop key="key3">value3</prop>
</props>
</property>
<property name="maps">
<map>
<entry key="key1" value="value1"></entry>
<entry key="key2" value="value2"></entry>
<entry key="key3" value="value3"></entry>
</map>
</property>
</bean>
</beans>
分享到:
相关推荐
实现了XML注入Bean,为bean注入bean,构造注入,Map,List,Set,Property 注入
<beans xmlns="http://www.springframework.org/schema/beans" ...-- p命名空间注入属性依然要设置set方法 --> 风清扬" p:age="230"/> <!--c命名空间注入要求有对应参数的构造方法 --> </beans>
6.8.1. 在Spring中使用AspectJ来为domain object进行依赖注入 6.8.1.1. @Configurable object的单元测试 6.8.1.2. 多application context情况下的处理 6.8.2. Spring中其他的AspectJ切面 6.8.3. 使用Spring IoC来...
String methodName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1); Method m = o.getClass().getMethod(methodName, beanObject.getClass().getInterfaces()[0]); m....
public void setId(int id) { this.id = id; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserAge()...
(1)setter方法注入:(2)调用带参的构造方式注入:(3)p名称空间注入:(4)spel表达式注入:复杂类型注入(1)List是一种按照序号标识的集合(2)Set与List相似但是元素不允许重复(3)Map则是一种自定的键值对...
As with normal Spring EL expressions, Thymeleaf allows you to access a series of objects from them including the context variables map (the #vars object). In fact, you are allowed to surround your ...
-- <property name="successUrl" value="/blog/drug/list"/>--> 06 <property name="unauthorizedUrl" value="/unauthorized.jsp"/> 07 <!-- The 'filters' property is not necessary since any declared ...
<tx:method name="set*" propagation="REQUIRED" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" /> *" propagation="REQUIRED" read-only="true" /> *" ...
List list = this.userService.getUserLists(map); this.initResult(model, list, map); return new ModelAndView("pagerList"); } catch (Exception e) { e.printStackTrace(); } return ...
<property column="name" name="name" operate="set" /> <property column="status" operate="set" /> 有嵌套的查询 id="queryModelList3" collection="test_sample"> class="java.lang.String...
protected List<Content> getList(Map, TemplateModel> params, Environment env) throws TemplateException { Integer[] ids = DirectiveUtils.getIntArray(PARAM_IDS, params); if (ids != null) { //根据内容...
list、set、map问题? 答:set 不允许重复,无序 list 允许重复,有序 map 成对的数据结构,键值必须具有唯一性 Servlet和CGI的区别? 答:Servlet与CGI的区别在于Servlet处于服务器进程中,它通过多线程方式允许...
4. 为Bean配置集合(List,Set,Map) 266 5. 调用构造方法创建Bean 271 6. 指定Bean引用与自动装配 276 (二) AOP 278 1. AOP简介 278 (三) Spring 3.X 新特性(JavaConfig,SpEL)简介 285 1. JavaConfig 285 2. SpEL...
6、以上所有类型的集合,List,Set,Map(有些局限性) However nothing is added to the list of classes that can be created (i.e. put up for remoting) without you declaring it. 2、 The Converters DWR已经默认...