Java Tutorial/Spring/Singleton — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 15:22, 31 мая 2010
Содержание
BeanFactory PreInstantiate Singletons Integration
File: context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="instantiationCounterClass"
class="InstantiationCounterClass"/>
</beans>
Prototype Singleton
File: context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="primeIterator"
class="PrimeIterator" singleton="false">
<property name="start" value="1000"/>
</bean>
</beans>
Singleton Scope And Prototype Scope
File: context.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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean id="singleMe" class="java.lang.String" scope="singleton">
<constructor-arg type="java.lang.String" value="Singleton"/>
</bean>
<bean id="prototypeMe" class="java.lang.String" scope="prototype">
<constructor-arg type="java.lang.String" value="Prototype"/>
</bean>
</beans>
Spring Prototype
File: context.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="prototypeClient"
class="SpringPrototypeClient">
<property name="message1" ref="message"/>
<property name="message2" ref="message"/>
</bean>
<bean id="message" class="EmailMessage" singleton="false"/>
</beans>