Spring入门学习——使用工厂Bean和Utility Schema定义集合
2017-04-21 10:49
381 查看
使用基本集合标记定义集合时,不能指定集合的实体类,例如LinkedList、TreeSet或TreeMap,而且不能通过将(集合定义为可供其他Bean引用)的(单独Bean)在不同的Bean中(共享集合)。解决方法:
(1)使用对应的集合工厂Bean,如ListFactoryBean,SetFactoryBean,MapFactoryBean
(2)使用在Spring2.x引入的util schema使用集合标记,<util:list>、<util:set>和<util:map>
仍然使用之前博客中一直使用的生成序列号代码作为理解实践<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="sequenceGenerator" class="com.cgy.springrecipes.sequence.SequenceGenerator">
<property name="prefixGenerator" ref="datePrefixGenerator"/>
<property name="initial" value="10000"/>
<property name="suffixes">
<bean class="org.springframework.beans.factory.config.SetFactoryBean">
<property name="targetSetClass[/b]">
<value>java.util.TreeSet</value>
</property>
<property name="sourceSet[/b]">
<set>
<value>5</value>
<value>10</value>
<value>20</value>
</set>
</property>
</bean>
</property>
</bean>
<bean id="datePrefixGenerator" class="com.cgy.springrecipes.sequence.DatePrefixGenerator">
<property name="pattern" value="yyyyMMdd"/>
</bean>
</beans>
(1)使用对应的集合工厂Bean,如ListFactoryBean,SetFactoryBean,MapFactoryBean
(2)使用在Spring2.x引入的util schema使用集合标记,<util:list>、<util:set>和<util:map>
仍然使用之前博客中一直使用的生成序列号代码作为理解实践<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="sequenceGenerator" class="com.cgy.springrecipes.sequence.SequenceGenerator">
<property name="prefixGenerator" ref="datePrefixGenerator"/>
<property name="initial" value="10000"/>
<property name="suffixes">
<bean class="org.springframework.beans.factory.config.SetFactoryBean">
<property name="targetSetClass[/b]">
<value>java.util.TreeSet</value>
</property>
<property name="sourceSet[/b]">
<set>
<value>5</value>
<value>10</value>
<value>20</value>
</set>
</property>
</bean>
</property>
</bean>
<bean id="datePrefixGenerator" class="com.cgy.springrecipes.sequence.DatePrefixGenerator">
<property name="pattern" value="yyyyMMdd"/>
</bean>
</beans>
相关文章推荐
- Spring 学习总结 使用静态工厂创建Bean
- Spring学习笔记 关于Bean定义的重用-使用abstract以及parent标签属性
- Spring入门学习——调用静态工厂方法创建Bean
- Spring入门学习——使用Spring的FactoryBean创建Bean
- spring学习小结7_使用工厂方法来配置bean:静态工厂方法和实例工厂方法
- Spring学习--使用 utility scheme 定义集合及 p命名空间
- Spring入门学习——调用一个实例工厂方法创建Bean
- Spring学习之使用静态工厂方法以及实例工厂方法配置bean
- Spring入门学习——使用Bean感知容器
- Spring学习笔记 关于Bean定义的重用-使用abstract以及parent标签属性
- Spring 学习笔记2 - Bean的定义与Ioc的使用
- Spring学习笔记 使用Non-Static Factory(非静态工厂类)创建Bean
- 使用Spring注解完成Bean的定义
- Spring学习笔记 使用annotation配置实现Bean的auto-wiring (自动绑定)
- Spring中使用标签定义bean
- 【第五章】Spring表达式语言 之 5.4在Bean定义中使用EL—跟我学spring3
- 【第五章】Spring表达式语言 之 5.4在Bean定义中使用EL—跟我学spring3
- 学习Spring(二) 调用静态工厂方法创建Bean
- Spring 学习手札(二)通过XML定义Bean
- 【第五章】Spring表达式语言 之 5.4在Bean定义中使用EL—跟我学spring3