Spring3HelloWorld:
package springExample;
public class Spring3HelloWorld {
public void sayHello(){
System.out.println("Hello Spring 3.0");
}
public int add(int a, int b)
{
return a+b;
}
}
Spring3HelloWorldTest:
package springExample;
//Please refer to http://www.roseindia.net/spring/index.shtml for more details
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class Spring3HelloWorldTest {
public static void main(String[] args) {
XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("SpringHelloWorld.xml"));
Spring3HelloWorld myBean = (Spring3HelloWorld) beanFactory.getBean("Spring3HelloWorldBean");
myBean.sayHello();
int c = myBean.add(2, 3);
System.out.println("c::::::::::::::"+c);
}
}
SpringHelloWorld.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" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="Spring3HelloWorldBean" class="springExample.Spring3HelloWorld" />
No comments:
Post a Comment