在Spring中配置非Singleton
2007-12-23 12:35:23 来源:WEB开发网核心提示:/File: beans.xml<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>&l
///////////////////////////////////////////////////////////////////////////////////////
//File: beans.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- non-singleton examples -->
<bean id="nonSingleton" class="java.lang.String" singleton="false">
<constrUCtor-arg>
<value>Value</value>
</constructor-arg>
</bean>
</beans>
///////////////////////////////////////////////////////////////////////////////////////
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class NonSingleton {
public static void main(String[] args) {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"build/beans.xml"));
String s1 = (String)factory.getBean("nonSingleton");
String s2 = (String)factory.getBean("nonSingleton");
System.out.println("Identity Equal?: " + (s1 ==s2));
System.out.println("Value Equal:? " + s1.equals(s2));
System.out.println(s1);
System.out.println(s2);
}
}
//File: beans.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- non-singleton examples -->
<bean id="nonSingleton" class="java.lang.String" singleton="false">
<constrUCtor-arg>
<value>Value</value>
</constructor-arg>
</bean>
</beans>
///////////////////////////////////////////////////////////////////////////////////////
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class NonSingleton {
public static void main(String[] args) {
BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
"build/beans.xml"));
String s1 = (String)factory.getBean("nonSingleton");
String s2 = (String)factory.getBean("nonSingleton");
System.out.println("Identity Equal?: " + (s1 ==s2));
System.out.println("Value Equal:? " + s1.equals(s2));
System.out.println(s1);
System.out.println(s2);
}
}
(出处:http://www.cncms.com)
[]
- ››配置远程客户机使用命名管道协议访问SQL服务器
- ››配置SQL Server2005以允许远程访问
- ››配置ISA Server以创建站点到站点VPN 连接之一
- ››配置ISA Server以创建站点到站点VPN 连接之二
- ››配置ISA Server以创建站点到站点VPN 连接之三 启用...
- ››配置VPN服务器中的L2TP/IPSEC:ISA2006系列之二十...
- ››配置单网卡的ISA缓存服务器:ISA2006系列之二十七...
- ››配置Win2008作为远程访问SSL-VPN服务器之一
- ››配置Win2008作为远程访问SSL-VPN服务器之二
- ››配置Win2008作为远程访问SSL-VPN服务器之三
- ››配置Windows Server 2003群集服务
- ››配置DHCP服务器过程详解
更多精彩
赞助商链接