Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Creating Spring MVC Template Project

  1. #1

    Default 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. #2
    Join Date
    Jan 2013
    Location
    us
    Posts
    2

    Default

    Hi,

    Give me some tips for template creation.

  3. #3

    Default Creating MVC Template

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

  4. #4

    Default

    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 at 08:48 PM. Reason: update

  5. #5
    Join Date
    Jan 2013
    Posts
    5

    Default

    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?

  6. #6

    Default Spring MVC tempate project

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

  7. #7
    Join Date
    Jan 2013
    Posts
    5

    Default

    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.

  8. #8

    Default Creating MVC Template

    Quote 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 at 08:04 PM. Reason: update info

  9. #9

    Default

    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.

  10. #10

    Default 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

Posting Permissions

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