Announcement Announcement Module
Collapse
No announcement yet.
Spring MVC with JPA support setup Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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?

      Comment


      • #4
        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.

        Comment


        • #5
          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?

          Comment


          • #6
            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.

            Comment


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

              Comment


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

                Comment


                • #9
                  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.

                  Comment


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

                    Comment

                    Working...
                    X