0% found this document useful (0 votes)
18 views3 pages

Write A Program To Display Name and Age of Emplyoee Using Beans - Applicationcontext Program

This document describes a program that uses Spring to display the name and age of an employee. It defines a Simple Java class with name and age attributes along with getters and setters. An applicationContext XML configures a bean of type Simple with hardcoded values for name and age. A test class loads the application context and retrieves the configured Simple bean to call its displayInfo method and output the name and age.

Uploaded by

Viraj Pitale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Write A Program To Display Name and Age of Emplyoee Using Beans - Applicationcontext Program

This document describes a program that uses Spring to display the name and age of an employee. It defines a Simple Java class with name and age attributes along with getters and setters. An applicationContext XML configures a bean of type Simple with hardcoded values for name and age. A test class loads the application context and retrieves the configured Simple bean to call its displayInfo method and output the name and age.

Uploaded by

Viraj Pitale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Write a program to display name and age of emplyoee using beans - ApplicationContext

Program:

Simple.java

package simplemsg;

public class simple {

//Attributes

String name;

int age;

//getter and setter

/**

* @return the name

*/

public String getName() {

return name;

/**

* @param name the name to set

*/

public void setName(String name) {

this.name = name;

/**

* @return the age

*/

public int getAge() {

return age;

}
/**

* @param age the age to set

*/

public void setAge(int age) {

this.age = age;

//utility method

void displayInfo()

System.out.println("Name : "+name+"\n Age: "+age);

applicationcontext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="simplemsg" class="simplemsg.simple">

<property name="name" value="veda"></property>

<property name="age" value="10"></property></bean>

</beans>

SimpleTest.java

package simplemsg;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SimpleTest {

private static ApplicationContext ctx;

public static void main(String[] args) {

// TODO Auto-generated method stub

ctx=new ClassPathXmlApplicationContext("applicationcontext.xml");

simple s1=(simple)ctx.getBean("simplemsg");

s1.displayInfo();

You might also like