Pages

get our extension

Search program

Sunday 23 June 2013

Write Your First String Program

First create a POJO class
Right Click on
SRC ( inside application 1)à newà class
Write any package name like I’m writing com.alok and give class name like Book then click finish

package com.alok;

public class Book
{
      private String title;
      private String author;
      public Book()
      {
            System.out.println("Book()");
      }
      public String getTitle() {
            System.out.println("getTitle");
            return title;
      }
      public void setTitle(String title) {
            System.out.println("set title");
            this.title = title;
      }
      public String getAuthor() {
            System.out.println("getAuthor");
            return author;
      }
      public void setAuthor(String author) {
            System.out.println("set Author");
            this.author = author;
      }
     
}

Inside config.xml register this POJO class with a unique bean id

<?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.xsd">


<bean id="b1" class="com.alok.Book">
      <property name="title" value="java made easy"></property>
      <property name="author" value="prince"></property>

</bean>

</beans>




 à b1 is pointing to a object which is already created then we are calling setTitle and setAuthor 

à inside config.xml, for every bean tag, object is created

à All Setter method is calling before delimiter itself

Now Develop a Client Program

src-->com.alok-->new--> class

BookClient.java

package com.alok;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BookClient {
public static void main(String[] args) {
BeanFactory fac=new ClassPathXmlApplicationContext(new String[]{"config.xml"});
System.out.println("----111-----");
Book b1=(Book)fac.getBean("b1");
System.out.println("----222-----");
System.out.println(b1.getTitle());
System.out.println(b1.getAuthor());
}

}
à  While creating beanFactory object inside config.xml, corresponding setter and getter method is calling

try to understand output
output:-
Book()
set title
set Author
Book()
set title
set Author
----111-----
----222-----
getTitle
java made easy
getAuthor
prince

First Step in STC

When STC is opened then click on
 FileànewàSpring Project
Give any name, for example I’m giving application 1
Now Right click on
 application 1à propertiesà Java Build Path
Click on adds external JARs and first adds all jar files inside spring-framework-4.0.0.M1/libs
Again click on adds external JARs and add all jar files inside commons-logging-1.1.3

Right Click on  src (inside application 1)ànewàSpring bean configuration file
Give any name like I’m giving config.xml
Contents already exist inside config.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"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


</beans>


Now write your first spring program

Monday 10 June 2013

Getting Started with Spring

(1) First Download Spring FrameWork
-----> latest version is 4.0

click below link to download spring Framework 4.0
http://www.springsource.org/download/community

download only
spring-framework-4.0.0.M1-dist.zip(sha1)47.6 MB
Three inside this Zip folder.
      ---1. docs
      ---2. libs --------> there are several jar files.
      ---3. schema

----------> The whole spring framework is developed in JAVA


(2). Second Download Commons-logging- 1.1.3
   ----> these jar files are using for internally logging purpose

click below link to download Commons-logging- 1.1.3

from here download commons-logging-1.1.3-bin.zip

(3).  Last Download Spring Tool Suite
        
click below link to download Spring Tool Suite

from here download depend on your computer configuration(32bit or 64 bit)





After download Spring Tool Suite-3.2.0
--->click on STC icon. now you are ready to write your first spring program
     (Very similar to Eclipse)

(All download links are from http://www.springsource.org   and all right reserved@Spring by Pivotal )