Results 1 to 10 of 10

Thread: Spring MVC with JPA support setup

  1. #1
    Join Date
    Apr 2012
    Posts
    7

    Default Spring MVC with JPA support setup

    Hi guys,

    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.

  2. #2
    Join Date
    May 2008
    Posts
    34

    Default

    Hi,
    have you seen the PetClinic project? I think it does what you need:
    https://src.springframework.org/svn/...tclinic/trunk/

    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.

    Cheers,
    Michael.

  3. #3
    Join Date
    Apr 2012
    Posts
    7

    Default

    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?

  4. #4
    Join Date
    May 2008
    Posts
    34

    Default

    Hi,
    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.

    Cheers,
    Michael.

  5. #5
    Join Date
    Apr 2012
    Posts
    7

    Default

    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?

  6. #6
    Join Date
    May 2008
    Posts
    34

    Default

    Hi,
    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.

    Cheers,
    Michael.

  7. #7
    Join Date
    Apr 2012
    Posts
    7

    Default

    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'?

  8. #8
    Join Date
    Apr 2012
    Posts
    7

    Default

    To be more precise, I have 60 tables, therefore I need this automation of JPA entities, otherwise I have to create them by hand.

  9. #9
    Join Date
    May 2008
    Posts
    34

    Default

    Hi,
    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.

    Cheers,
    Michael.

  10. #10
    Join Date
    Apr 2012
    Posts
    7

    Default

    Actually,if you have a JPA project,then you can create JPA entities from tables.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •