12:47 pm - Saturday July 22, 2017

Spring Autowire Autodetect With NoArgument Constructor Example Eclipse

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

ProjectStructure:

 

 

 

 

 

 

 

 JarFile1:

 

 

 

 

 

 

 

 

 

 

 

 

 

JarFiles:

 

 

 

 

 

Autowiring.xml:

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

	<bean id="circle" class="com.candidjava.Circle" />
	<bean id="triangle" class="com.candidjava.Triangle" />

	<bean id="targetAutodetect" autowire="autodetect" class="com.candidjava.Shape" />
	<bean id="targetByType" autowire="byType" class="com.candidjava.Shape" />
</beans>

Circle.java:

package com.candidjava;

public class Circle {

}

Shape.java:

package com.candidjava;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class Shape {

	private Circle circle;
	private Triangle Triangle;

	public Shape() {
		System.out.println("empty constructor");
	}

	public Shape(Circle circle) {
		System.out.println("constructor");
	}

	public void setCircle(Circle circle) {
		System.out.println("This is circle");
	}

	public void setDisplay(Circle circle) {
		System.out.println("This is display method");
	}

	public static void main(String[] args) {
		BeanFactory factory = new XmlBeanFactory(new FileSystemResource(
				"config\\autowiring.xml"));

		Shape shape = null;

		System.out.println("\nUsing autodetect:\n");
		shape = (Shape) factory.getBean("targetAutodetect");

	}
}

Triangle.java:

package com.candidjava;

public class Triangle {

}

OUTPUT:

 

 

 DOWNLOAD+SOURCECODE+JARFILES

 

 

 

 

 

 

                                   

 

Filed in: Z-A Spring Codes

Comments are closed.