how to setup Spring for swing desktop application

Hi in this post of spring tutorial ill discuss about how to set up spring for desktop based application.It is very simple.

First of all you need to download Spring jar . You can do google for latest spring jar file or download spring jar files here. Or Here

Now we need to add these jar files in our application .

Create Java project from top left corner of eclipse from File menu > New >java project . Give name to your application and hit finish.

spring for desktop application


Now we need to add spring lib with the application. To add spring lib in application right click on your project  >properties . A window will prompt .Click on java built path left  > Add library 

Spring  for desktop application

Select User Library and click on Next

spring for desktop application

In new window you will see all the user library that you may have created earlier .Click on user library on RHS .

spring for desktop application

In new window click on New and enter name of library that you want and click ok .In my case i have given name SpringLib .

spring for desktop application

Till now we have created a directory for our project where we will put our spring jar files .Now we need to add jar files in this directory. Click on Add external jars and select all the spring jars that you have downloaded. Then click Ok.

spring for desktop application

Till we have added spring jar files in our project .

Now we can do coding stuff . Yo need to create spring.xml and place it in src folder.

Here is directory Structure of application .

spring for desktop application

In spring.xml we will define our bean classes .We have bean class Message .So we need to give fully qualified name in spring.xml . And if we need to pass any  value to any property of bean class then we can pass it by using property tag like this.

Here is our Bean class with a single property message.

Now in class we will define main method and will access bean class property .To create object we have give spring.xml as an argument in constructor of ClassPathXmlApplicationContext . Spring container manage instantiating of object.  spring container read information from spring.xml and create object. context.getBean(” “) method create a generic object, so we need to cast it.

When we will run this application will see this window .Here we have access bean property message and set it as title and button Label.

spring for desktop application

Download source code of this application here

This is all in this post of spring tutorial. I will show up soon with next post of tutorial very soon.

Comments are closed.