alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (factory-methods.xml)

This example Spring Framework source code file (factory-methods.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

bean, doctype, doctype, no, no, public, spring//dtd, the, the, unnamed, unnamed, utf-8

The Spring Framework factory-methods.xml source code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

	<bean id="default" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="defaultInstance">
		<!-- No constructor-arg elements -->
		<property name="stringValue">setterString
	</bean>

	<bean id="defaultTestBean" factory-bean="default" factory-method="getTestBean"
			init-method="haveBirthday" destroy-method="destroy"/>
			
	<bean id="defaultTestBean.protected" factory-bean="default" factory-method="protectedGetTestBean"
			init-method="haveBirthday" destroy-method="destroy"/>
			
	<bean id="defaultTestBean.private" factory-bean="default" factory-method="privateGetTestBean"
			init-method="haveBirthday" destroy-method="destroy"/>

	<bean id="testBeanOnly" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance">
		<constructor-arg>
	</bean>

	<bean id="null" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="nullInstance"/>

	<bean id="nullWithProperty" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="nullInstance" init-method="getName" scope="prototype">
		<property name="stringValue">setterString
	</bean>

	<bean id="full" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance">
		<constructor-arg index="0">
		<constructor-arg index="1">27
		<constructor-arg index="2">gotcha
	</bean>
	
	<bean id="fullWithNull" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance">
		<constructor-arg index="0">
		<constructor-arg index="1">27
		<constructor-arg index="2" type="java.lang.Integer">
	</bean>

	<bean id="fullWithGenericNull" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance">
		<constructor-arg>
		<constructor-arg type="int">27
		<constructor-arg type="java.lang.Integer">
	</bean>

	<bean id="fullWithAutowire" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance" autowire="constructor">
		<constructor-arg index="0" ref="juergen"/>
		<constructor-arg index="1" value="27"/>
	</bean>

	<bean id="stringToBeAutowired" class="java.lang.String">
		<constructor-arg value="gotchaAutowired"/>
	</bean>

	<bean id="defaultPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
			scope="prototype" factory-method="defaultInstance">
		<!-- No constructor-arg elements -->
		<property name="stringValue">setterString
	</bean>

	<bean id="testBeanOnlyPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance" scope="prototype">
		<constructor-arg>
		<property name="stringValue">testBeanOnlyPrototypeDISetterString
	</bean>

	<bean id="fullPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance" scope="prototype">
		<constructor-arg type="int">27
		<constructor-arg>gotcha
		<constructor-arg>
	</bean>
	
	<bean id="noMatchPrototype" class="org.springframework.beans.factory.xml.FactoryMethods"
			factory-method="newInstance" scope="prototype">
		<constructor-arg index="0">
		<constructor-arg index="1">27
		<constructor-arg index="2">gotcha
		<constructor-arg index="3">bogus
	</bean>

	<bean id="listInstance" class="org.springframework.beans.factory.xml.FactoryMethods"
		  factory-method="listInstance"/>

	<bean id="juergen" class="org.springframework.beans.TestBean">
		<property name="name">Juergen
	</bean>

	<!--
		The class is the factory class, not the created class.
	-->
	<bean id="externalFactoryMethodWithoutArgs" 
			class="org.springframework.beans.factory.xml.TestBeanCreator"
			factory-method="createTestBean">
	</bean>
	
	<bean id="externalFactoryMethodWithArgs" class="org.springframework.beans.factory.xml.TestBeanCreator"
			factory-method="createTestBean">
		<constructor-arg index="0">Rod
		<constructor-arg>33
	</bean>
	
	<bean id="instanceFactoryMethodWithoutArgs"
			factory-bean="instanceFactory"
			factory-method="defaultInstance"/>

	<!-- Unnamed bean with factory-bean declaration -->
	<bean factory-bean="instanceFactory" factory-method="defaultInstance"/>

	<bean id="testBeanWithInnerFactoryMethod" class="org.springframework.beans.TestBean">
		<property name="friends">
			<list>
				<!-- Unnamed bean with factory-bean declaration -->
				<bean factory-bean="instanceFactory" factory-method="defaultInstance"/>
			</list>
		</property>
	</bean>

	<bean id="instanceFactory" class="org.springframework.beans.factory.xml.InstanceFactory" scope="singleton">
		<property name="factoryBeanProperty">instanceFactory
	</bean>

	<bean name="javaMailSession" class="javax.mail.Session" factory-method="getDefaultInstance">
		<constructor-arg>
			<props>
				<prop key="mail.smtp.auth">true
				<prop key="mail.smtp.host">
				<prop key="mail.smtp.port">
				<prop key="mail.smtp.user">someuser
				<prop key="mail.smtp.password">somepw
			</props>
		</constructor-arg>
	</bean>

</beans>

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework factory-methods.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.