好久没有写代码了 连spring注入都忘记了,真是老了不行了,记录下吧
java代码
package hua; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; public class DomainTest { 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 Set<String> getSets() { return sets; } public void setSets(Set<String> sets) { this.sets = sets; } public List<String> getLists() { return lists; } public void setLists(List<String> lists) { this.lists = lists; } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } public Map<String, String> getMaps() { return maps; } public void setMaps(Map<String, String> maps) { this.maps = maps; } @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("\nSets:\n"); for (Iterator<String> iterator = getSets().iterator(); iterator .hasNext();) { sb.append(iterator.next() + " "); } sb.append("\nLists:\n"); for (Iterator<String> iterator = getLists().iterator(); iterator .hasNext();) { sb.append(iterator.next() + " "); } sb.append("\nProperties:\n"); for (Enumeration<String> e = (Enumeration<String>) getProperties() .propertyNames(); e .hasMoreElements();) { String key = (String) e.nextElement(); sb.append(key + " : " + getProperties().getProperty(key) + " "); } sb.append("\nMaps:\n"); for (Object o : getMaps().keySet()) { sb.append(o + " : " + getMaps().get(o) + " "); } return sb.toString(); } }
spring配置文件:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="domainTest" class="hua.DomainTest"> <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="key-1" value="value-1"/> <entry key="key-2" value="value-2"/> <entry key="key-3" value="value-3"/> </map> </property> </bean> </beans>
测试
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( "appcontext.xml"); DomainTest psb = (DomainTest) context.getBean("domainTest"); System.out.println(psb); }
相关推荐
Spring的一些配置信息(date map and so on) Spring Date Map List Set Properties 自己写了一个属性编辑器,主要对Date型数据进行操作
Spring容器IOC和di的整个启动过程: 38 3.8 spring中的继承 38 拓展spring为类中的属性赋值: 40 小结: 47 面向接口编程: 47 4 面向切面编程 52 4.1 代理模式 52 代理模式拓展: 52 4.1.1 JDK动态代理 58 JDK动态...
spring构造参数,set方法,类对象属性的注入,还有数组,list,map,properties对象的依赖注入。
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来...
在Spring中可以装配4种集合类型属性:List、set、Map和Properties。与这四种集合对应的标签是、、、。CollectionBean是一个包含上述4种集合类型的JavaBean,代码如下:
该xml文件不仅仅是Spring框架初次使用时的主配置文件,而且该文件里面包含了java.util里面的List,Set,Map,Properties等的命名空间,支持在配置文件中定义外部的集合,便于参数注入的复用性
public void setId(int id) { this.id = id; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserAge()...
装配bean——集合类型注入值: 本文介绍数组、list集合、set集合、map集合、properties的注值 博客原文地址:http://blog.csdn.net/tingzhiyi/article/details/52104203
springboot 的配置文件加载顺序 ... 本系列校训 用免费公开视频,卷飞培训班哈人!打死不报班,赚钱靠狠干!...YAML 对象、数组、List、Map、Set的行内写法与缩进写法 YAML 位置 第一个位置 第二个位置 其它位置
本系统是基于RBAC授权和基于用户授权的细粒度权限控制通用平台,并提供单点登录、会话管理和日志管理。接入的系统可自由定义组织、角色、权限、资源等。用户权限=所拥有角色权限合集+用户加权限-用户减权限,优先级...
protected List<Content> getList(Map, TemplateModel> params, Environment env) throws TemplateException { Integer[] ids = DirectiveUtils.getIntArray(PARAM_IDS, params); if (ids != null) { //根据内容...
-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 添加 mybatis-config配置上去。--> <!-- 扫描...
11. Spring transaction properties 29 编程/代码 30 1. 编程题: 用最有效率的方法算出2乘以8等於几? 30 2. 我们在web应用开发过程中经常遇到输出某种编码的字符,如iso8859-1等,如何输出一个某种编码的字符串? 30 3....
著作:《java jdk 5.0学习笔记》、《java se 6技术手册》、《spring技术手册》等 译作:《ajax实战手册》、《jquery实战手册(第2版)》 个人网站:http://openhome.cc 目录 《java jdk 7学习笔记》 chapter1 ...