Previous Next vertical dots separating previous/next from contents/index/pdf

Generating Spring Artifacts

Generating Spring artifacts by hand is a tedious process. To assist you, Workshop Studio can automatically generate Spring configuration and beans (service and DAO interface and implementation classes) from persistence mappings.

To use Spring, you must generate service and DAO classes. These classes have an interface and implementation, to allow you to easily switch persistence models (e.g., from Hibernate to JPA).

Workshop studio can generate the following artifacts:

  1. The DAO interface
  2. The DAO implementation
  3. The service interface
  4. The service implementation
  5. Configuration files

Generating Spring Artifacts from Persistence Mappings

To generate the Spring artifacts, you must

  1. Configure your project for Spring.
  2. Generate the Spring files and update the configuration.

Step 1: Configuring your Project for Spring

To configure your project for Spring, you can either add the Spring facet when you create the project or you can add the facet to an existing project by clicking Project > Properties, expanding Project Facets and clicking Add/Remove Project Facets .

Choose Spring and click Next.

The next dialog allows you to download and install the Spring libraries.

Click Add to get the Spring libraries. The next dialog allows you to download the Spring libraries from the BEA web site, or use Spring libraries that are installed locally.

Once you have selected the option you prefer, click Next to continue. The final screen allows you to choose which files should be included. By default, the entire spring.jar library is included.

After you select the files to include, click Finish to complete the installation of the Spring facet and libraries for this project.

Click Finish to close the Add/Remove Project Facets Spring dialog.

Finally, click OK to close the Properties dialog.

Step 2: Generate Spring Files and Update Configuration

To initiate the Spring artifact generation, right click on the project name in the AppXplorer view and choose File > New > Other. Expand Spring and click on Generate Spring ORM Classes and click Next.

On the Generate Spring ORM Classes dialog, note that the Beans File field has been filled in when you added the Spring facet to your project. (If you wish to use another file, you can do that by choosing Project > Properties and choosing Spring Bean.)

Click Add to add a Spring service(s).

On the New ORM Service dialog, you must specify:

  1. A name for the service in the Service Name box.
  2. The bean(s) that will be managed by this service.
  3. The exception that will be thrown by the service methods (by default, java.lang.Exception).
  4. The package(s) where the service and DAO classes will be generated. In the sample screen above, all of the files will be created in the same package (called com.bea.beans) but you can specify different packages for each file if you wish.

Click OK to continue.

Click Next on the Generate Spring ORM Classes dialog to continue.

The next dialog allows you to specify Velocity templates to be used for code generation. If you create your own template directory, files in that directory will override template files of the same name in the default template directory.

Click Finish to generate the Spring beans and update the Spring configuration file.

The Spring classes are generated in the package that you specified. The bean classes contain methods for standard CRUD (Create, Read, Update and Delete) operations.

Note that only the DAO implementation class is dependent on a specific framework. This allows you to change ORM frameworks easily and quickly, without rewriting client code.

Working with Spring Artifacts

Once the Spring artifacts are generated, you can easily navigate from the configuration files to the bean by Control-clicking on a class name, with the Spring IDE (bundled with Workshop Studio).

 

 

Skip navigation bar   Back to Top