11:32 am - Wednesday May 24, 2017

Spring simple program (FileSystemXmlApplicationContext) 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

<pre><?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></pre>

HelloWorld.java

<pre>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");
	}
}</pre>
&nbsp;

MainTest.java

<pre>package com.candidjava;

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

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

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

	}
}</pre>

 

OUTPUT

 

DOWNLOADSOURCECODE + JARFILES

 

Filed in: Z-A Spring Codes

Comments are closed.