12:48 pm - Saturday July 22, 2017

Spring Autowiring no Example Program in 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="AutowireNo" autowire="no" class="com.candidjava.Shape">
		<property name="shapeName" value="Rectangle"></property>
	</bean>
</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 Triangle triangle;
	private Circle circle;

	String shapeName;

	public void setShapeName(String shapeName) {
		this.shapeName = shapeName;
		System.out.print("Shape ");
		System.out.print(shapeName);
	}

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

		Shape t = null;

		System.out.println("Using Auto wire no:\n");
		t = (Shape) factory.getBean("AutowireNo");

	}
}

Triangle.java:

package com.candidjava;

public class Triangle {
}

OUTPUT:

DOWNLOAD+SOURCECODE+JARFILES


Filed in: Z-A Spring Codes

Comments are closed.