Powered by Blogger.

Friday, 6 June 2014

Spring Start Program

By Shambhu Kumar  |  10:22 No comments

Bean

public class HelloWorld {
     private String msg;
      public String getMsg() {
           return msg;
     }
     public void setMsg(String msg) {
            this.msg = msg;
      }
}

spring-beans.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:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

      <bean id="messanger" class="com.shambhu.bean.HelloWorld">
        <property name="msg" value="Hello World" />
       </bean>
</beans>

Testing

public class HelloMain {


public static void main(String[] args) {
       ApplicationContext beanFactory = new  ClassPathXmlApplicationContext("spring-beans.xml");
        HelloWorld messanger= (HelloWorld) beanFactory.getBean("messanger");
        System.out.println(messanger.getMsg());
}
}




pom.xml
<properties>
<spring.version>4.0.3.RELEASE</spring.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>

Jun 06, 2014 10:40:38 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4f114133: startup date [Fri Jun 06 22:40:38 IST 2014]; root of context hierarchy
Jun 06, 2014 10:40:38 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-beans.xml]
Hello World


Author: Shambhu Kumar

Hello, I am Author, decode to know more: In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In commodo magna nisl, ac porta turpis blandit quis. Lorem ipsum dolor sit amet.

0 comments:

Recent Articles

© 2014 Learning Java. WP themonic converted by Bloggertheme9. Published By Gooyaabi Templates
TOP