![]() |
![]() |
![]() |
![]() |
Generating Spring artifacts by hand is a tedious process. To assist you, Workshop 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 can generate the following artifacts:
To generate the Spring artifacts, you must
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.
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:
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.
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).
![]() ![]() |