简体   繁体   中英

Why won't basic spring 4 sample run with Eclipse kepler?

I am using the sample project code here that i've downloaded from the following: http://javahash.com/spring-4-mvc-hello-world-tutorial-full-example/

Direct link here: http://javahash.com/wp-content/uploads/2014/02/Spring4MVCHelloWorld.zip

I have Eclipse Kepler SR2 (J2EE), Tomcat 7 64-bit, Java 7.

The project does not appear to be a web project, so I add "Dynamic Web Module" version 3.0 and "Java" (version 1.7) to it. I right click, maven install, which appears to run fine. When I try to actually deploy it on tomcat, it does not give any errors in the console, but when the browser window pops up it shows a 404

http://localhost:8080/Spring4MVCHelloWorld/



HTTP Status 404 - /Spring4MVCHelloWorld/

--------------------------------------------------------------------------------

type Status report

message /Spring4MVCHelloWorld/

description The requested resource is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.39

That said, how do I get this "basic" example running in eclipse? Anyone able to get this working successfully? It feels like it should be more trivial than the 5 hours I've spent on trying to get this sample code working to no avail.

UPDATE: Still continues to fail despite using Tomcat 7.0 server.

  1. Download the sample, extract contents to workspace directory.
  2. "Import Existing Project" in Eclipse
  3. Since there is no "Run On Server" option, I right click on the imported project directory and hit "Properties".
  4. I go to "Project Facets" and check 2 things: "Dynamic Web Module" (3.0) and "Java" (1.7) and hit apply then "Ok".
  5. I right click on the project Spring4MVCHelloWorld and click "Maven"->"Update Project". Then I click "Run On Server".
  6. There are no errors in the console, but the web browser that pops up in eclipse shows a HTTP STATUS 404.

I tried going to:

http://localhost:8080/Spring4MVCHelloWord/hello

and the same:

HTTP Status 404 - /Spring4MVCHelloWorld/hello

shows up, but the tomcat shows up as:

Apache Tomcat/7.0.53

Note that this is the 64-bit version. What steps am I missing? How do I get around this silent failing?

As far as I can see your controller only maps to /hello , which means your URL should be:

http://localhost:8080/Spring4MVCHelloWorld/hello

Another thing that might be interesting to you is that if your having problems with certain project facets (like Dynamic Web Module ) not being recognized, you can usually fix them by righ clicking your project, opening the Maven menu and choosing Update Project .

Apart from what Dimitri stated, your log seems to indicate that you are using

Apache Tomcat/6.0.39

That version of Tomcat does not support ServletContainerInitializer which your Spring web application depends on for configuration. Upgrade to a Tomcat version 7+.


It seems like the Maven update doesn't work for you (or for me).

First, go into Properties -> Deployment Assembly . You need to get rid of Web Content if it's there and add src/main/webapp (which is a maven convention). You also need to add the Maven Dependencies as shown below.

在此输入图像描述

Finally, and this might not be necessary, delete the web.xml provided to you and re-create it by selecting and right clicking Deployment Descriptor in the Project Explorer and clicking Generate Deployment Descriptor Stub .

Also, make sure your Java Build Path in the Properties has a Java 7+ version of the JRE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM