Skip to main content

Hello world application in spring using xml bean configuration.

1. Download the spring3.0 jars from following location.

2. Create a new Java project and include the following jars into your java build path. 

1.   org.springframework.aop-3.0.6.RELEASE.jar
2.   org.springframework.asm-3.0.6.RELEASE.jar
3.   org.springframework.aspects-3.0.6.RELEASE.jar
4.   org.springframework.beans-3.0.6.RELEASE.jar
5.   org.springframework.context-3.0.6.RELEASE.jar
7.   org.springframework.core-3.0.6.RELEASE.jar
8.   org.springframework.expression-3.0.6.RELEASE.jar
9.   org.springframework.instrument-3.0.6.RELEASE.jar
10. org.springframework.instrument.tomcat-3.0.6.RELEASE.jar
11. org.springframework.jdbc-3.0.6.RELEASE.jar
12. org.springframework.jms-3.0.6.RELEASE.jar
13. org.springframework.orm-3.0.6.RELEASE.jar
14. org.springframework.oxm-3.0.6.RELEASE.jar
15. org.springframework.spring-library-3.0.6.RELEASE.libd
16. org.springframework.test-3.0.6.RELEASE.jar
17. org.springframework.transaction-3.0.6.RELEASE.jar
18. org.springframework.web-3.0.6.RELEASE.jar
19. org.springframework.web.portlet-3.0.6.RELEASE.jar
20. org.springframework.web.servlet-3.0.6.RELEASE.jar
21. org.springframework.web.struts-3.0.6.RELEASE.jar

All the jars are present in spring-framework-3.0.6.RELEASE\dist folder

3. Create a new HelloWorldBean and include the following code.

public class HelloWorldBean {
      private String message;
      public HelloWorldBean(){
      public HelloWorldBean(String message){
            this.message = message;
      public void setMessage(String message){
            this.message = message;
      public String getMessgae(){
            return message;

4. Create a new main class and include the following code.

package com.bean.execution;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
public class HelloWorldExecution {
public static void main(String args[]){
         BeanFactory factory = new XmlBeanFactory(new ClassPathResource("BeanConfig.xml"));
         HelloWorldBean helloWorldBean = (HelloWorldBean)factory.getBean("HelloWorld");
         helloWorldBean.setMessage("Modified message");

5. Create a BeanConfig xml file inside the src folder and include the following code.

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

   <bean id="HelloWorld" class="">
         <property name="message">
               <value>Hello World...!</value>

6. Execute the HelloWorldExecution main method

    I got the following errors.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(
    at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(
    at com.bean.execution.HelloWorldExecution.main(
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    ... 9 more

7. For resolving this issue, I download the Apache common logging jar from following location and I added the "commons-logging-1.1.1.jar" into my java build path.
      Now execute the HelloWorldMain class.

    The result of the application is
      Nov 30, 2011 12:33:12 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [BeanConfig.xml]
Hello World...!
Modified message


Popular posts from this blog

Ext JS 4 – Creating web page using Ext.container.Viewport class and region propery

The Ext.container.Viewport is used for creating general web page and region property is used for splitting web page into different parts. Ext.container.Viewport is a specialized container represents the viewable area of the application (the browser area). It render itself to the document body, there is no need for providing renderTo property and it automatically sizes itself to size of the browser viewport. The viewport also re-size the child elements based on view area(based on browser width and height). The default layout of the viewport is border layout and we can customize this property according to our requirements. The viewport does not provide any scrolling. If necessary, the child elements(generally panels) within viewport needs to provide a scroll feature by using autoScroll property. See the below example for better understanding. This is Home.js file placed into app/view folder. Ext.define('MyApp.view.Home', { extend : 'Ext.container.Viewport&#

Getting servlet init parameter that is defined in web.xml

1. Create a new dynamic web project using eclipse. 2. Create a one new servlet and include the following code. package com.controller ; import; import javax.servlet .ServletConfig; import javax.servlet .ServletException; import javax.servlet .annotation.WebServlet; import javax.servlet .http.HttpServlet; import javax.servlet .http.HttpServletRequest; import javax.servlet .http.HttpServletResponse; @ WebServlet ( "/LoginController" ) public class LoginController extends HttpServlet {                 private static final long serialVersionUID = 1L;                 public LoginController() {         super ();     }     protected void doPost( HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException {                                 ServletConfig config = getServletConfig ();                                 System.out.println( "Init parameter user nam

Simple Login Application Using Spring MVC and Hibernate – Part 1

 I hope developers working in web application development might hear about MVC architecture. Almost all technologies provide support for MVC based web application development, but the success is based on many factors like reusable of the code, maintenance of the code, future adaption of the code, etc..,  The success of the Spring MVC is “ Open for extension and closed for modification ” principle. Using Spring MVC the developers can easily develop MVC based web application. We don’t need any steep learning curve at the same time we need to know the basics of spring framework and MVC architecture. The Spring MVC consists of following important components. 1. Dispatcher servlet 2. Controller 3. View Resolver 4. Model Spring MVC - Overview  The overall architecture of Spring MVC is shown here.  1. When “Dispatcher Servlet” gets any request from client, it finds the corresponding mapped controller for the request and just dispatches the request to the corresponding contro