Getting Started Tutorial

About this tutorial

Tutorial duration estimation: 15 minutes.

Download springfuse-example.zip and follow the instructions below

In this tutorial you are going to learn how to generate your first Java/Spring/Hibernate based project using Springfuse. All in all, you should not type more than 3 commands from your console to have your first project running.

Anybody can follow this tutorial and discover Springfuse. All you need is Java and Maven2, you do not need to have a database to follow the tutorial. We provide an example database.

Note: Step 1 & 2 can be done without signing up, however in Step 3 you will need to signup and login into springfuse.com to generate the project.

Understand how Springfuse works

Springfuse reverses your database schema and uses the result of the extraction as an entry point to generate your Spring-based Java Project.

Obviously, Springfuse service cannot access your database. Instead Springfuse relies on you to:

  • 1- Run a simple Maven plugin that reverses your database schema and dumps into a file the result of the extraction.
  • 2- Upload this file to Springfuse, so the generation can take place on our server

You might be wondering what kind of information is dumped into this file. Is the data dumped ?
The clear answer is no. We dump only its structure such as the table names, the column names, the indexes, the primary key, etc.

To keep this tutorial simple, we are not going to ask you to use your database, instead we will use an embedded database.

Step 1 - Software Requirements

Java SE Development Kit (JDK) 5, or above

You can download it for free from http://java.sun.com.

Maven 2.1.x or above

You can download it for free from Apache's Maven site.

If you are behind an http proxy, you must tell maven how to go through your proxy.

For those who are new to Maven, simply make sure that your Maven installation is clean. For example, type from a console

c:\tutorial>mvn -version

You should have an output similar to this:

c:\tutorial> mvn -version
Apache Maven 2.1.0 (r755702; 2009-03-18 20:10:27+0100)
Java version: 1.5.0_15
OS name: "windows vista" version: "6.0" arch: "x86" Family: "windows"

Step 2 - Create and Reverse a database schema

step 2.1 Unzip the example

Download and unzip springfuse-example.zip then open a console, and go to the folder containing the Maven2 pom.xml.
c:\tutorial\springfuse-example>dir
20/01/2009  15:27             5 743 pom.xml
21/01/2009  21:54             3 815 README.txt
27/01/2009  15:41              src

Notice, the src folder, it contains the H2 database SQL scripts to create the embedded database that we are going to reverse. You can take a look at the scripts, even modify them. However, we recommend to keep them as is if this is your first attempt.

step 2.2 About the database schema

The graph below represents the database schema that we are going to create.


There are 3 important tables in this schema, not required though. These tables are ACCOUNT, ROLE and ACCOUNT_ROLE. By convention when Springfuse encounters such tables it assumes they should be used for authentication/authorization and thus generates some glue code for Spring Security. The ACCOUNT table has other implications in relation with Hibernate filters that are beyond the scope of this tutorial.

The fourth table, DOCUMENT, is here to illustrate one of Springfuse's great feature, the file upload/download support in Spring MVC. Since this table's columns follow some conventions in their naming and type, Springfuse assumes that it should generate some additional source code so you can upload and download some files!

step 2.3 Create and reverse the database schema example !

Type 'mvn initialize' to create and reverse the database schema shown above.

c:\tutorial\springfuse-example>mvn initialize
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building springfuse-example
[INFO]    task-segment: [initialize]
[INFO] ------------------------------------------------------------------------
[INFO] [sql:execute {execution: Create and initialize the database}]
[INFO] Executing file: c:\tutorial\springfuse-example\src\main\sql\h2\drop.sql
[INFO] Executing file: c:\tutorial\springfuse-example\src\main\sql\h2\create.sql
[INFO] Executing file: c:\tutorial\springfuse-example\src\main\sql\h2\comment.sql
[INFO] Executing file: c:\tutorial\springfuse-example\src\main\sql\h2\init.sql
[INFO] 45 of 45 SQL statements executed successfully
[INFO] [springfuse:extract {execution: Extract database Meta Data}]
[INFO] Ready to extract the database schema
[INFO] Connecting to database jdbcUrl=jdbc:h2:~/.h2/quickstartdb
[INFO] Connected OK
[INFO] database Product Name: H2
[INFO] database schema extracted
[INFO] File data-model.springfuse passed reverse conversion OK
[INFO] File data-model.springfuse created successfully
[INFO] You are now ready to upload data-model.springfuse to http://www.springfuse.com/ 
       and generate your project!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Jan 27 16:10:07 CET 2009
[INFO] Final Memory: 4M/8M
[INFO] ------------------------------------------------------------------------

This simple command has done 2 things:

  • 1- It has created the database quickstartdb in the file ~/.h2/quickstartdb
  • 2- It has reversed this quickstartdb database schema and dumped the result of the extraction in the file data-model.springfuse.

Congratulations! you just did the hardest part, the next step should be a piece of cake for you.

Step 3 - Generate a new project on www.springfuse.com

From here, you should be a Springfuse user, if you still have not created a free account: signup here
Assuming you have signed in, you can click on Generate New Project. There is a simple form to fill.

Here is a tip: give your project the same name as your database, that is quickstartdb, this will allow you to run your project out-of-the-box without any additional JDBC configuration!

Choose any Java package, for example: com.yourock

Select the file data-model.springfuse

Click on Generate, in less than 5 seconds, your project is ready for download!

Step 4 - Run your project

Download your project, unzip it, open a console and go to the root folder of the unzipped project. Here are the files it contains:

c:\tutorial\quickstartdb\quickstartdb>dir
02/02/2009  18:07               633 .classpath
02/02/2009  18:07               630 .project
02/02/2009  21:16    REP            .settings
02/02/2009  18:07            11 479 license.txt
02/02/2009  18:07               892 notice.txt
02/02/2009  18:07            41 469 pom.xml
02/02/2009  18:07             1 222 README.txt
02/02/2009  21:16    REP            src

From this folder, run the following command:

c:\tutorial\quickstartdb>mvn -Ph2 jetty:run
[... 
     Skip Maven2 output. Be patient, it may take some time to download all the jar dependencies such as 
     spring, spring-mvc, spring-security, hibernate, etc.
 ...]

2009-01-27 16:50:03.043::INFO:  Started SelectChannelConnector@0.0.0.0:8080
[INFO] Started Jetty Server            

The '-Ph2' argument tells Maven to use the 'h2' database profile defined in the pom.xml.

If you followed all the previous steps, your project is now up and running !

Open http://localhost:8080/ and sign in using either user/user or admin/admin. As an admin, you have more privileges, try to create a new Document entry, this involves the upload of a file. Then you can try to download it...

Step 5 - Import your project into Eclipse

You can now import the project into Eclipse as a Maven project.

You will need to install the Maven2 plugin for Eclipse.

The screenshot below represents the package dependencies of the generated code, as you can see, there is no cyclic dependencies and the layers are well separated.



The graph is generated by the ispace plugin, it is not part of the generated project, however you can install it easily.

Thank you for following this tutorial.

You can now reverse your own database schema