2:09 am - Saturday January 21, 2017

Spring simple program without using any Editor (core Spring)

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

springconfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
    "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org./dtd/spring-beans.dtd">
<beans>
	<bean id="mybean" class="Inject">

		<property name="name">
			<value>mathan</value>
		</property>
		<property name="age">
			<value>25</value>
		</property>
		<property name="company">
			<value>C I T</value>
		</property>
		<property name="email">
			<value>mathanlalsait@gmail.com</value>
		</property>
		<property name="address">
			<value>1103760000</value>
		</property>
	</bean>

</beans>

Main.java

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class Main {

	public static void main(String[] args) {
		XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
				"springconfig.xml"));
		Inject demo = (Inject) beanFactory.getBean("mybean");

		System.out.println(demo);
	}
}

Inject.java

class Inject {

	private String name;
	private int age;
	private String company;
	private String email;
	private String address;

	public void setAddress(String address) {
		this.address = address;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String toString() {
		return "Name :" + name + "\n" + "Age:" + age + "\n" + "Company: "
				+ company + "\n" + "E-Mail: " + email + "\n" + "Address: "
				+ address;
	}
}

OUTPUT

DOWNLOAD+SOURCECODE

Filed in: Z-A Spring Codes

Comments are closed.