12:43 am - Monday August 21, 2017

Spring simple program(ClassPathXmlApplicationContext) with using 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

Project Structure

Jar Files 

How To Add Jar Files: 

Spring-config.xml

<?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="helloBean" class="com.candidjava.HelloWorld">
		<property name="welcomestring" value="World" />
	</bean>

</beans>

HelloWorld.java

package com.candidjava;

public class HelloWorld {
	private String welcomestring;

	public void setWelcomestring(String welcomestring) {
		this.welcomestring = welcomestring;
	}

	public void printHello() {
		System.out.println("This is my Hello" + welcomestring + " Program");
	}
}

MainTest.java

package com.candidjava;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainTest {
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"com\\candidjava\\Spring-config.xml");

		HelloWorld obj = (HelloWorld) context.getBean("helloBean");
		obj.printHello();

	}
}

OUTPUT

 

DOWNLOAD + SOURCECODE + JAR FILES

Filed in: Z-A Spring Codes

Comments are closed.