Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • XML Configuration based spring framework example

    • 0
    • 4
    • 1
    • 3
    • 0
    • 0
    • 0
    • 0
    • 381
    Comment on it

    Hello guys
    Bellow example will help you to develop XML configuration based spring framework project,here I have develop example to display "Hello Bhagwan" message using beans.
    Please create project and follow bellow setps:


    Step :1 Add bellow jar files :

    antlr-runtime-3.0.1
    org.springframework.aop-3.1.0.M2
    org.springframework.asm-3.1.0.M2
    org.springframework.aspects-3.1.0.M2
    org.springframework.beans-3.1.0.M2
    org.springframework.context.support-3.1.0.M2
    org.springframework.context-3.1.0.M2
    org.springframework.core-3.1.0.M2
    org.springframework.expression-3.1.0.M2
    commons-logging-1.1.1

    Step :2 Create HelloBhagwan.java and put bellow contents :

    package com.bhagwan;
    
    public class HelloBhagwan{
       private String message;
    
       public void setMessage(String message){
          this.message  = message;
       }
    
       public void getMessage(){
          System.out.println("Your Message : " + message);
       }
    }
    

    Setp : 3 Create MainApp.java and put bellow contents

    package com.bhagwan;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class MainApp {
       public static void main(String[] args) {
          ApplicationContext context = 
                 new ClassPathXmlApplicationContext("Beans.xml");
    
          HelloWorld obj = (HelloBhagwan) context.getBean("helloBhagwan");
    
          obj.getMessage();
       }
    }
    

    Step : 4 Create Beans.xml and put bellow code :

    <?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="helloBhagwan" class="com.bhagwan.HelloBhagwan">
           <property name="message" value="Hello Bhagwan!"/>
       </bean>
    
    </beans>
    

    Thank you

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: