Note that there are some explanatory texts on larger screens.

plurals
  1. POTomcat / Spring integration returning 404
    primarykey
    data
    text
    <p>I'm having a similar issue to <a href="https://stackoverflow.com/questions/9260777/http-status-404-on-spring-3-1-mvc-app">HTTP Status 404 on Spring 3.1 MVC app</a></p> <p>But I have not made the same mistakes as that poster did, yet I'm still getting a 404.</p> <p>web.xml file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt; &lt;display-name&gt;Test&lt;/display-name&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;servlet&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt; </code></pre> <p>I am able to load index.jsp but not an actual controller.</p> <p>dispatcher-servlet.xml file:</p> <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt; &lt;!-- enable Spring’s component scanning --&gt; &lt;context:component-scan base-package="com.test" /&gt; &lt;!-- process the @RequestMapping annotations at the class level --&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /&gt; &lt;!-- process the @RequestMapping annotations at the method level --&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;/bean&gt; </code></pre> <p></p> <p>Controller</p> <pre><code>package com.test.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.ui.Model; @Controller public class BenchController { @RequestMapping(value = "/bench", method = RequestMethod.GET) @ResponseBody public String welcome(Model model) { return "yo"; } </code></pre> <p>}</p> <p>I am able to go to localhost:8080/Test/index.jsp but localhost:8080/Test/bench returns a 404.</p> <p>I am using eclipse, if that helps.</p> <p>EDIT 1:</p> <p>This is the logging.properties. I can't find any of the logs apart from out log.</p> <pre><code>handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler ############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ 1catalina.org.apache.juli.FileHandler.level = FINE 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.FileHandler.prefix = catalina. 2localhost.org.apache.juli.FileHandler.level = FINE 2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.FileHandler.prefix = localhost. java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter ############################################################ # Facility specific properties. # Provides extra control for each logger. ############################################################ org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler # For example, set the com.xyz.foo logger to only log SEVERE # messages: #org.apache.catalina.startup.ContextConfig.level = FINE #org.apache.catalina.startup.HostConfig.level = FINE #org.apache.catalina.session.ManagerBase.level = FINE #org.apache.catalina.core.AprLifecycleListener.level=FINE </code></pre> <p>Interesting enough, I'm not sure where catalina.base variable is being defined.</p> <p>EDIT 2:</p> <p>pom.xml</p> <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.test&lt;/groupId&gt; &lt;artifactId&gt;Test&lt;/artifactId&gt; &lt;version&gt;0.1&lt;/version&gt; &lt;packaging&gt;war&lt;/packaging&gt; &lt;properties&gt; &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt; &lt;spring.version&gt;3.1.0.RELEASE&lt;/spring.version&gt; &lt;/properties&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; &lt;version&gt;2.3.2&lt;/version&gt; &lt;configuration&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt; &lt;configuration&gt; &lt;webXml&gt;/WebContent/WEB-INF/web.xml&lt;/webXml&gt; &lt;/configuration&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-core&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-context&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-web&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;log4j&lt;/groupId&gt; &lt;artifactId&gt;log4j&lt;/artifactId&gt; &lt;version&gt;1.2.16&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/project&gt; </code></pre> <p>I don't see log4j in my dependency tree even though it's in my pom file.</p> <p>EDIT 3:</p> <p>Here's how I created my project in eclipse:</p> <ol> <li>New Maven Project (m2 eclipse plugin)</li> <li>I selected Simple Project</li> <li>Filled out group/artificat id and selected war as my packaging</li> <li>I right clicked on my project in the project folder window and selected Properties</li> <li>I clicked on Project Facets and converted it when prompted</li> <li>I selected "Dynamic Web Module" and clicked ok</li> </ol> <p>Once I had all that done , I started adding the dispatcher, updated the pom with spring, etc.</p> <p>EDIT 4:</p> <p>Alright, I'm finally getting somewhere. After commenting out this lines in web.xml:</p> <pre><code>&lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p>I was able to directly deploy the application through tomcat manager. Now I'm getting </p> <pre><code>java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml] </code></pre> <p>It seems it's trying to find the dispatcher-servlet.xml under /WEB-INF folder. After looking inside the war file, I cannot locate the file at all. Every time I place the servlet xml in that folder, it seems to be removed. I can put it under any other folder, but for some reason when I do, it still seems to search for the file under /WEB-INF even after updating the web.xml to reference the new location.</p> <p>EDIT 5:</p> <p>Here's an update on my web.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" </code></pre> <p>xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <a href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" rel="nofollow noreferrer">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a>" version="2.5"></p> <pre><code> &lt;display-name&gt;Test&lt;/display-name&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;servlet&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;WEB-INF/classes/dispatcher-servlet.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;WEB-INF/classes/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;WEB-INF/classes/log4j.properties&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;/web-app&gt; </code></pre> <p>After explicitly adding the location of applicationContext and dispatcher-servlet. catalina.out says:</p> <pre><code>Mapped URL path [/bench] onto handler 'benchController' Mapped URL path [/bench.*] onto handler 'benchController' Mapped URL path [/bench/] onto handler 'benchController' Mapped URL path [/bench] onto handler 'benchController' Mapped URL path [/bench/*] onto handler 'benchController' FrameworkServlet 'dispatcher': initialization completed in 245 ms </code></pre> <p>But when going to localhost:8080/Test/bench - it still returns a 404. I cannot acess index.jsp when I deploy through tomcat manager, but I can if I deploy through eclipse. No other output by catalina.out.</p> <p>Log:</p> <pre><code>127.0.0.1 - - [20/Feb/2012:14:41:13 -0800] "GET /Test/ HTTP/1.1" 200 182 127.0.0.1 - - [20/Feb/2012:14:41:19 -0800] "GET /Test/ HTTP/1.1" 200 182 127.0.0.1 - - [20/Feb/2012:14:41:24 -0800] "GET /Test/bench HTTP/1.1" 404 1012 </code></pre> <p>SOLUTION:</p> <p>I followed the instructions provided below and inside the project folder, from the command line I ran mvn eclipse:eclipse -Dwtpversion=2.0 so that eclipse can import the project correctly. I'm working on figuring out how to do this all through eclipse to avoid having to manually do this every time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload