Products Docs & Support Community

Introduction to the Spring Framework in NetBeans IDE


This document shows you how to install the Spring Framework and run it in NetBeans IDE. The Spring Framework is a popular open source application framework that can make J2EE development easier. It consists of a container, a framework for managing components, and a set of snap-in services for web user interfaces, transactions, and persistence.

This tutorial takes advantage of Craig MacKay's Spring NetBeans Module, and documents the flash demo he has prepared that guides you through the installation process. At the end of this tutorial, you will have a module installed in your IDE that provides the following support for the Spring Framework:

  • Framework Support (enables the Spring Framework as an option when creating a new web application)
  • Spring XML Catalog (provides Spring related XSD and DTD's to enable XML code completion)
  • Integrated Library Management (installs libraries required for the Spring Framework, as well as additional required libraries)

For more information on the Spring Framework. For a more fine-grained explanation of how Spring Framework artifacts behave and interact with other objects in an application, visit the official Spring Framework Reference Documentation, or consult the Spring Framework API.

For details on the Spring NetBeans Module. If you are familiar with the Spring Framework, you are welcome to contribute to the development of the Spring NetBeans Module.


Expected duration: 20 minutes


The following topics are covered below:


Getting the Software

Before beginning, make sure you have the following software installed on your computer:

  • NetBeans IDE 5.5 (download)
  • Java SE Development Kit (JDK™) version 5.0 or higher (download)
  • The Spring NetBeans Module (download)

Note: As an alternative to downloading the IDE and JDK separately, consider downloading the Java SE Development Kit 6u1 with NetBeans IDE 5.5 Bundle.


Installing the Module

Begin by installing the Spring NetBeans Module in the IDE:

  1. Launch NetBeans IDE and choose Update Center from the Tools menu. The Update Center wizard opens. Under Select Location of Modules, select the Install Manually Downloaded Modules (.nbm Files) option. Click Next.
  2. In Step 2, Select Modules to Install, click the Add button located to the right of the window, and browse to the location where you downloaded the module. Select the module, click OK, then click Next.
  3. Notice that Spring Framework Support is listed under the Include to Install pane:



    Click Next.
  4. Accept the license agreement that displays, and the Update Center begins automatically downloading the module into the IDE. Upon completion, click Next.
  5. In Step 4, View Certificates and Install Modules, click the Include checkbox to the left of the Spring Framework Support. When the Unsigned Module alert box pops up, simply click Yes - this module can be trusted. Then click Finish.
  6. Finally, when the Restart the IDE window displays, make sure the Restart the IDE option is selected and click OK. The IDE needs to be restarted in order for changes to take effect.

Creating a New Project

Now that the module is installed, you can create a new project for a web application using the Spring Framework:

  1. Choose New Project (Ctrl+Shift+N) from the IDE's File menu. Under Categories select Web. Under Projects select Web Application. Click Next.
  2. In Project Name, type in SpringWebApp. From the Server drop-down list, select the server you plan to work with. Leave all other settings at their defaults and click Next.
  3. In Step 3, the Frameworks panel, notice that we just installed the Spring NetBeans Module, Spring Framework 2.0 is now listed:



    Select the corresponding checkbox and click Finish. The IDE creates a project template for the entire application, including all metadata, as well as the project's Ant build script. You can view the template structure from the Projects window. Also note that the project's top level index.jsp file, provided as an entry point to the application, opens by default in the Source Editor.

Running the Project

Let us see what happens when we try running the project in the IDE:

  • Right-click the project node and choose Run Project (alternately, press F6). The IDE automatically starts your server if it is not already running, and deploys the application to it. The application runs and employs the Spring MVC DispatcherServlet using the configuration data contained in dispatcher-servlet.xml. Note any output displayed in the IDE's Output window (Ctrl+4). The generated output should complete with a BUILD SUCCESSFUL message:



    The IDE's default browser starts up, and you see the generated output of the welcome page view (/WEB-INF/jsp/index.jsp):


Browsing the Project's Structure

Now that you know the project can be deployed and run successfully, look at how the Spring Framework is integrated in the project's structure:

  • In the Projects window, completely expand the Web Pages > WEB-INF node. Note that the following Spring Framework artifacts have been created for you:

    Spring Framework artifacts:

    classes/ehcache.xml:
    allows fine-tuning of ehcache settings, which might be needed for persistence-related features (e.g. if ehcache is used with Hibernate).

    classes/log4j.properties:
    reads the log4jConfigLocation context parameter and reads the log4j configuration specified as the value. This is useful during development and allows you to fine-tune log output.

    jsp/: contains JSP pages used to render views for the application.

    tld/: contains tag library definition files

    applicationContext.xml:
    defines beans which make up the application context for the framework and provides their availability to all dispatcher servlets.

    dispatcher-servlet.xml:
    defines beans used for specifying controllers and Spring MVC related features.

    jdbc.properties:
    contains configuration data which can be applied to values of other XML documents.

    web.xml:
    defines application listeners and paths to XML files that specify beans.

  • Expand the Libraries node. Note that the Spring Framework JAR files have been included in the new project:








    Note: From the Libraries node, you can also add new libraries and JAR files. To do so, choose the appropriate action from the Libraries node's right-click menu.

    To remove any JAR files, choose Remove from the right-click menu of a selected JAR file. Alternatively, you can make any changes to libraries by accessing the Project Properties dialog (choose Properties from the right-click menu of the project node, then under Categories, select Libraries).

You can now begin developing the application according to your needs. For example, you can start modifying the application context (application-context.xml) to add new services and DAO objects, or add new controllers to the application's dispatcher servlet (dispatcher-servlet.xml).


Next Steps

This concludes the Introduction to the Spring Framework in NetBeans IDE tutorial. This document demonstrated how to install the Spring Framework into NetBeans IDE, and introduced you to the IDE's interface for developing in the framework.

You are encouraged to continue learning about the Spring Framework by working through other tutorials in NetBeans IDE, such as Thomas Risberg's Developing a Spring Framework MVC Application Step-by-Step tutorial.

For related and more advanced tutorials on netbeans, see the following resources:

  • Spring Framework Hands-on Lab. A comprehensive series of lectures and labs using the Spring Framework in NetBeans IDE.
  • Adding Support for a Web Framework. A basic guide describing how to add support by installing a web framework plugin using the NetBeans Update Center.
  • NetBeans IDE 5.5 Tutorial for Web Applications. A detailed tutorial that teaches you how to build a complete web application using a composite view, front controllers, JSP pages, and servlets.
  • Introduction to the JSF Framework. The first document in a series that covers the basics of using the JavaServer Faces framework to code web applications in NetBeans IDE.
  • Introduction to Java EE 5 Technology. An introduction to the major concepts of the Java EE 5 specifications and how they relate to hands-on programming.


top