package com.amit.bean;
//private class HelloBean --> we can keep any scope (public , private)
public class HelloBean
{
public HelloBean() //--> Parameterized constructor not allowed
{
System.out.println("...Bean Instantiation...");
}
public String sayHello()
{
return "Welcome";
}
}
//private class HelloBean --> we can keep any scope (public , private)
public class HelloBean
{
public HelloBean() //--> Parameterized constructor not allowed
{
System.out.println("...Bean Instantiation...");
}
public String sayHello()
{
return "Welcome";
}
}
====================================================================
package com.amit.test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.amit.bean.HelloBean;
public class Test {
public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloBean bean = (HelloBean)context.getBean("helloBean");
String msg = bean.sayHello();
System.out.println(msg);
}
}
====================================================================
<?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="helloBean" class="com.amit.bean.HelloBean">
</bean>
</beans>
====================================================================
No comments:
Post a Comment