Drop Down

Saturday, September 21, 2019

Spring_App_2

package com.amitsoft.test;

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

import com.amitsoft.beans.HelloBean;

public class Test {

public static void main(String[] args)
{
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloBean bean = (HelloBean)context.getBean("helloBean");
//bean.setName("Amit"); //---> use xml to set values
String msg = bean.sayhello();
System.out.println(msg);
}

}


========================================================================

package com.amitsoft.beans;

public class HelloBean 
{
private String name;
public String getName() {
return name;
}

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

public String sayhello()
{
return "Hello "+getName()+" !";
}
}

========================================================================

<?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.amitsoft.beans.HelloBean">
<property name="name" value="Amit"></property>
</bean>
</beans>

========================================================================

No comments:

Post a Comment

Java 8 Notes Pics