In Netbeans Go File --> New Project
select java webapplication like show below:
Click Next--->click Next-->and select framework in framework window like show below:
Click -->Next
Now its ready for coding part....
Create java class bean.java
--------------------------------------Coding Start-------------------------------------
public class bean {
public void myexample()
{
System.out.println("Hello my spring by ganesh");
}
}
public void myexample()
{
System.out.println("Hello my spring by ganesh");
}
}
--------------------------------------Coding End-------------------------------------
Create Main class main.java
--------------------------------------Coding Start-------------------------------------
public class main {
public static void main(String[] args) {
XmlBeanFactory xml=new XmlBeanFactory(new ClassPathResource("myxml.xml"));
bean b=(bean)xml.getBean("mybean");
b.myexample();
}
}
public static void main(String[] args) {
XmlBeanFactory xml=new XmlBeanFactory(new ClassPathResource("myxml.xml"));
bean b=(bean)xml.getBean("mybean");
b.myexample();
}
}
--------------------------------------Coding End-------------------------------------
Create Spring xml Configuration file myxml.xml like show below:
myxml.xml
--------------------------------------Coding Start-------------------------------------
<?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-3.0.xsd
">
<bean id="mybean" class="bean"/>
</beans>
<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-3.0.xsd
">
<bean id="mybean" class="bean"/>
</beans>
--------------------------------------Coding End-------------------------------------
Run your main class
Ouput :
Hello my spring by ganesh.
0 comments:
Post a Comment