Wednesday, 2 October 2013

First Java Spring Program:

Having Basic Knowledge Of Spring Application Context and Container, We will look into a very basic Working Program developed in eclipse,
  • Pr-Requisites of spring framework:
    • Either Spring Tool Suite OR Eclipse need to be installed.
    • In Spring Tool Suite Create New --> Spring Project Will Do All necessary configurations.
    • In Eclipse, User Library need to be configured containing all jars of spring,
      • Menu Bar ->> Window -->> Preferences -->> Search for User Libraries -->> Create New Library -->> Add External Jars -->> add all jars listed in below figure into it.










Now We Going To write XML, Interface and Classes Which Are Used In Program, This Program Is Basically An Example Of Creating a Bean In Spring Framework

Create An Interface Called Figure: With draw() method


A Class Triangle Implementing Figure

Class Contains 2 property height and type, A Constructor accepting 2 argument (type and height), and implementation of draw method of Figure interface.

Create Spring.xml in src folder of project for triangle bean used to create in spring context

Finally The Implementation Class Which Uses Aplication Context to inject the Triangle Bean into container
 

 At Last the project Folder structure Should Look Like
 
 Note That  Spring user library into the project and an additional .jar for logging information/Error messages from spring to console.


The Output

No comments:

Post a Comment