Announcement Announcement Module
Collapse
No announcement yet.
Creating Spring MVC Template Project Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating Spring MVC Template Project

    I am trying to create a Spring MVC template project according to the Spring Pro 3 book, chpt 16. It indicates to create a Spring Template Project, then select Spring MVC project then enter the name and base package. This is supposed to create a basic project with a hello world jsp page. I don't even get the webapp directory.

    As per the book, I added the following dependencies to the POM for the JPA backend:

    HTML Code:
    	<!-- JPA backend -->
     	<dependency> 
     		<groupId>org.springframework</groupId> 
     		<artifactId>spring-jdbc</artifactId> 
     		<version>${org.springframework-version}</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>org.springframework</groupId> 
     		<artifactId>spring-orm</artifactId> 
     		<version>${org.springframework-version}</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>org.springframework</groupId> 
     		<artifactId>spring-tx</artifactId> 
     		<version>${org.springframework-version}</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>org.springframework.data</groupId> 
     		<artifactId>spring-data-jpa</artifactId> 
     		<version>1.0.1.RELEASE</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>org.hibernate</groupId> 
     		<artifactId>hibernate-entitymanager</artifactId> 
     		<version>3.6.8.Final</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>javax.validation</groupId> 
     		<artifactId>validation-api</artifactId> 
     		<version>1.0.0.GA</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>org.hibernate</groupId> 
     		<artifactId>hibernate-validator</artifactId> 
     		<version>4.2.0.Final</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>com.h2database</groupId> 
     		<artifactId>h2</artifactId> 
     		<version>1.3.160</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>com.google.guava</groupId> 
     		<artifactId>guava</artifactId> 
     		<version>10.0.1</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>joda-time</groupId> 
     		<artifactId>joda-time</artifactId> 
     		<version>2.0</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>joda-time</groupId> 
     		<artifactId>joda-time-hibernate</artifactId> 
     		<version>1.3</version> 
     	</dependency> 
     	
     	<!-- JMS 
     	<dependency> 
     		<groupId>org.apache.activemq</groupId> 
     		<artifactId>activemq-core</artifactId> 
     		<version>5.5.1</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>org.springframework</groupId> 
     		<artifactId>spring-jms</artifactId> 
     		<version>${org.springframework-version}</version> 
     	</dependency> 
     	<dependency> 
     		<groupId>javax.jms</groupId> 
     		<artifactId>jms-api</artifactId> 
     		<version>1.1-rev-1</version> 
     	</dependency> 
     	-->
    I set the server to VMware vFabric tc Server Developer Edition v2.7

    I am using STS 3.1.RELEASE. As I said, there is no webapp directory created and no automatically created home.jsp file which print a Hello World message with the date and time.

    Thanks
    Mike

  • #2
    Hi,

    Give me some tips for template creation.

    Comment


    • #3
      Creating MVC Template

      Originally posted by johny brawn View Post
      Hi,

      Give me some tips for template creation.
      Thanks Johny, it's pretty straight forward. Create a new Spring Templete Project, then from the pop-up dialog select "Spring MVC Project", give it a name and a base package. That's pretty much it. The only other thing I did was add the following dependencies to the Pom: spring-jdbc, spring-orm, spring-tx, spring-data-jpa, hibernate-entitymanager, validation-api, hibernate-validator, h2, joda-time, jodat-time-hibernate, guava. These additions were for the back-end for the project.

      Supposedly after creating the project and adding the extra dependencies, you can click on the project, selec run, then run on server and it brings up VMware VFabric tc Server v2.7. You then see a Hello World jsp page at http://localhost:8080/ch17 (ch17 was the name of the project). But I don't even get a webapp directory created let alone a home.jsp file which contains the Hello World greeting.

      Comment


      • #4
        I solved the problem, actually there never was a problem. Spring was creating the files correctly, just not where I expected. The problem I am having now is error 404. When one creates a Spring MVC template project, you get a home.jsp file that displays Hello World and the time. You should not have to configure anything. When I do this and run it on the server it gives me a 404 file not found.

        When you create a Spring MVC project, just after creating it you have a home.jsp file. According to the book I'm using when you run the project on the server it will try to access http://localhost:8080/xx to display the home.jsp file. XX is the name of the project you created. In my case it's ch17, but when I run it on the server it tries to go to http://localhost:8080/prospring.
        Where is it getting this "prospring" from?

        Note: I downloaded Eclipse, got the STS and maven plug-ins and got this to work almost right away. The POM and *.xml files are all the same, but under STS 3.1 it still won't work. It still tries to go to http://localhost:8080/prospring3 instead of http://localhost:8080/test where test is the name of the project. I don't know where it is getting the prospring3
        Last edited by MikeT; Jan 5th, 2013, 09:48 PM. Reason: update

        Comment


        • #5
          Hi,

          I am also facing the same issue. In my case, instead of getting the project name it is adding the base package name.

          That is , my project name is LoginProject and base package is com.sample.login.

          if I give the URL like "http://localhost:8080/login, then it is able to display home.jsp content on browser.
          if I give URL like "http://localhost:8080/LoginProject, I am getting 404 error.

          I am not able to find, how it is happening. Could anybody help me on this?

          Comment


          • #6
            Spring MVC tempate project

            Originally posted by srujana View Post
            Hi,

            I am also facing the same issue. In my case, instead of getting the project name it is adding the base package name.

            That is , my project name is LoginProject and base package is com.sample.login.

            if I give the URL like "http://localhost:8080/login, then it is able to display home.jsp content on browser.
            if I give URL like "http://localhost:8080/LoginProject, I am getting 404 error.

            I am not able to find, how it is happening. Could anybody help me on this?
            I can't even get the home page if I put in the correct URL.

            Comment


            • #7
              I just given the example,I created LoginProject in STS selecting the Spring MVC project. Build the project without errors and deployed into the VMWare server.

              If I am trying to run the application that is http://localhost:8080/LoginProject, it is returning 404 error as resource not found error.
              but if I run the application like this http://localhost:8080/login(which is the base package name com.sample.login), it is producing the correct result.

              Note: In STS, Spring MVC Project defult controller is HomeController which will return the view home.jsp.

              Comment


              • #8
                Creating MVC Template

                Originally posted by srujana View Post
                I just given the example,I created LoginProject in STS selecting the Spring MVC project. Build the project without errors and deployed into the VMWare server.

                If I am trying to run the application that is http://localhost:8080/LoginProject, it is returning 404 error as resource not found error.
                but if I run the application like this http://localhost:8080/login(which is the base package name com.sample.login), it is producing the correct result.

                Note: In STS, Spring MVC Project defult controller is HomeController which will return the view home.jsp.
                Seens I tried my base package and all sorts of variants. Never could get it to work. The only way I got it to work was via running STS in Eclipse, but I can't experiment anymore until I get my pc back and I'm just sending it in today.

                I will say I was following the instructions in chp 16 of the Pro Spring3 book and those instructions did not mention anything about having to set the URL, you just run it in the server and it goes to the appropriate URL automatically.

                That's the way it worked under Eclipse.
                Last edited by MikeT; Jan 10th, 2013, 09:04 PM. Reason: update info

                Comment


                • #9
                  Martin,

                  So I got my pc back and restored it. Everything seems to be working fine, except I still have the problem I had before creating a Spring template MVC project. When I try to run it I get (among other server errors) the following:


                  SEVERE: ContainerBase.addChild: start:
                  org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/prospring3]]
                  at org.apache.catalina.util.LifecycleBase.start(Lifec ycleBase.java:154)
                  at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:901)
                  at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:877)
                  at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:618)
                  at org.apache.catalina.startup.HostConfig.deployDescr iptor(HostConfig.java:650)
                  at org.apache.catalina.startup.HostConfig$DeployDescr iptor.run(HostConfig.java:1582)
                  at java.util.concurrent.Executors$RunnableAdapter.cal l(Executors.java:439)
                  at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
                  at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:908)
                  at java.lang.Thread.run(Thread.java:662)

                  When I try to run on the server, the app goes to the page http://localhost:8080/prospring3. My default package was com.apress.prospring3.ch17. According to the book, it should have tried to go to http://localhost:8080/ch17. When I try to enter this address by hand, I still get an error 404, page not found.

                  When I run this in STS under Eclipse everything works fine. I am at a loss at this point to solve/explain this.

                  Comment


                  • #10
                    Creating MVC template project

                    So I am going to proceed with this project via Eclipse since no one has yet provided a solution as to why it won't work in SpringSource. One thing I noticed in doing this in both Eclipse and SpringSource is that when I define my base package, it only seems to take 3 components, i.e. if I define my base as com.apress.prospring3.ch17 I get a base package of com.apress.prospring3. So to try to stay in synch with the book, I've used a base package of com.prospring3.ch17 so the hello.jsp page is displayed at http://localhost:8080/ch17 instead of http://localhost:8080/prospring3 when I use the base package of com.apress.prospring3.ch17. I wish SpringSource 2.7 were till available as this is what the book used. Does STS 3.1 limit your base package to 3 levels?

                    Thanks
                    Mike

                    Comment


                    • #11
                      Yes, in Spring MVC template base package is limited to 3 levels. If we give more than 3 levels, it is trying to ended to 3rd level itself.
                      I.e In my project I have given,my base package as com.mycompany.spring.mvc which comtains 4 levels. But we when I do run on server of my project(ExampleProject) , in browser it is displayed as http://localhost:8080/spring instead of http://localhost:8080/ExampleProject.

                      could you please anybody help me what is the relation between base package and project name?
                      why context name is taking as base package last level name instead of project name?
                      Is this problem with only VWware vfabric server?

                      I was stuckup here since 10 days, can some one help me to proceed further?

                      Comment


                      • #12
                        Creating MVC Template

                        Originally posted by srujana View Post
                        Yes, in Spring MVC template base package is limited to 3 levels. If we give more than 3 levels, it is trying to ended to 3rd level itself.
                        I.e In my project I have given,my base package as com.mycompany.spring.mvc which comtains 4 levels. But we when I do run on server of my project(ExampleProject) , in browser it is displayed as http://localhost:8080/spring instead of http://localhost:8080/ExampleProject.

                        could you please anybody help me what is the relation between base package and project name?
                        why context name is taking as base package last level name instead of project name?
                        Is this problem with only VWware vfabric server?

                        I was stuckup here since 10 days, can some one help me to proceed further?
                        This must be new as of 3.0 or 3.1. In 2.7 I believe it took 4 levels. But this still does not address my problem of the fact that creating a Spring Template MVC project and running it on the server gives a 404 page not found error. I can only get it to work In STS under Eclipse. No one can seem to provide insight to that one.

                        Comment

                        Working...
                        X