Example to Demonstrate Spring Auto wiring constructor and autodetect Autowiring :-
<?xml version="1.0" encoding="UTF-8"?> <property name="prices"> <property name="products"> <bean id="setterInjectionBean" class="com.visualbuilder.beans.SetterInjectionBean" > </bean> <bean id="wrapperBeanAuto" class="com.visualbuilder.beans.WrapperConstructorBean" autowire="autodetect"></bean> |
WrapperConstructorBean.java
package com.visualbuilder.beans; public class WrapperConstructorBean { private ConstructorInjectionBean constructorInjectionBean; private DisposableInitBean disposableInitBean; private SetterInjectionBean setterInjectionBean; private TypeCollectionInjectionBean typeCollectionInjectionBean; public WrapperConstructorBean() { } public WrapperConstructorBean(CollectionInjectionBean collectionInjectionBean,ConstructorInjectionBean constructorInjectionBean, public CollectionInjectionBean getCollectionInjectionBean() { public void setCollectionInjectionBean(CollectionInjectionBean collectionInjectionBean) { public ConstructorInjectionBean getConstructorInjectionBean() { public void setConstructorInjectionBean(ConstructorInjectionBean constructorInjectionBean) { public DisposableInitBean getDisposableInitBean() { public void setDisposableInitBean(DisposableInitBean disposableInitBean) { public SetterInjectionBean getSetterInjectionBean() { public void setSetterInjectionBean(SetterInjectionBean setterInjectionBean) { public TypeCollectionInjectionBean getTypeCollectionInjectionBean() { public void setTypeCollectionInjectionBean( TypeCollectionInjectionBean typeCollectionInjectionBean) { |
AutoDetectExample1.java
| package com.visualbuilder.example; import org.springframework.context.ApplicationContext; import com.visualbuilder.beans.WrapperConstructorBean; public class AutoDetectExample1 { |
Output;-
Jun 8, 2008 10:17:17 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@c4bcdc: display name [org.springframework.context.support.ClassPathXmlApplicationContext@c4bcdc]; startup date [Sun Jun 08 10:17:17 IST 2008]; root of context hierarchy
Jun 8, 2008 10:17:17 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/visualbuilder/xml/spring-beans1.xml]
Jun 8, 2008 10:17:17 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@c4bcdc]: org.springframework.beans.factory.support.DefaultListableBeanFactory@15e83f9
afterPropertiesSet method is called
Geting the Bean Autowired byConstructor
Assigned Name is John Smith
Assigned Age is 25
Assigned Sex is M
Geting the Bean Autowired Autodetect
Assigned Name is John Smith
Assigned Age is 25
Assigned Sex is M
Jun 8, 2008 10:17:17 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@15e83f9: defining beans [test,disposableInitBean,collectionInjectionBean,typeCollectionInjectionBean,constructorInjectionBean,setterInjectionBean,wrapperBeanByName,wrapperBeanByType,wrapperBeanAuto,wrapperBeanConstructor]; root of factory hierarchy
Java Discussion
- - Difference between BMT an
- - Replace getParameterValue
- - Interviewing Next week -
- - Sudoku solver
- - Setting tab order in swin




