Apr 26th, 2012, 12:35 AM
Spring MVC with JPA support setup
I'm new to spring and I'm trying to setup an MVC project with JPA.
Every tutorial regarding MVC that I have found is rather simple (meaning that there is no database).
Now, I have 2 ideas.
The first one is to create one MVC project and put all my packages in this project. Unfortunately, in this approach, STS doesn't let me add Entities since this is not a JPA project.
My second approach is to create 4 seperate projects (one for domain, one for persistence, one for service and one for MVC), but again I cannot understand what kind of "template" projects I need to use for each one of them.
Thank you for your help.
Apr 26th, 2012, 08:22 AM
have you seen the PetClinic project? I think it does what you need:
Regarding the issue you're having with your libs, the "usual" way is to use Maven for that. That's also why you'll see a pom.xml file inside the petclinic project.
Apr 26th, 2012, 12:57 PM
Thank you Michael,
I have seen similar projects. What I cannot understand is how I initiate such a project in STS. Do I create a Maven project? If so, can I take advantage of STS spring specific features?
Or I create a Spring MVC project?
Apr 27th, 2012, 02:25 AM
the simplest way is to import it as a Maven project.
File -> Import -> Existing Maven project
It will then download all the dependencies you need, so this could take a while.
Apr 28th, 2012, 12:52 PM
Thanks Michael again,
but maybe we have misunderstood each other. My real question is not how do I setup petclinic. I have successfully done that.
But how I setup such a project from scratch. As a maven project?
Apr 28th, 2012, 06:15 PM
here is how you can do:
1) create a new Maven project, using "File -> new -> Maven project"
2) check "Create a simple project (skip archetype selection)" and click on "next"
3) Choose you groupId and artifactId, and choose "Packaging: war" (Web archive)
4) Click "Finish"
After that, it will only contain some empty folders and a pom.xml file. It will be your responsibility to create all the configuration files for Spring MVC, Spring and JPA. Of course you can copy them from the PetClinic project.
If you think you'll have some problems doing that, I could easily upload an empty project which contains configuration for Spring MVC and JPA already.
Apr 29th, 2012, 04:22 AM
Thank you Michael for your help.
But If you create a Maven project, can you take advantage of STS features like 'Spring elements' inside your project or 'JPA entities from tables'?
Apr 29th, 2012, 04:33 AM
To be more precise, I have 60 tables, therefore I need this automation of JPA entities, otherwise I have to create them by hand.
Apr 29th, 2012, 06:03 AM
any Java project in Eclipse can become a Spring project. Just right-click on your project and do "Spring -> add Spring project nature".
Are you sure that automation of JPA entities is a feature of Spring projects? I would have thought that this is only in case you are using Spring Roo.
Apr 29th, 2012, 06:09 AM
Actually,if you have a JPA project,then you can create JPA entities from tables.