Help with first spring MVC page using annotations
I'm trying to get http://localhost:8080/test to map to the index.jsp page.
The jsp file is stored in the folder:
/web-inf/jsp/index.jsp
what I have so far:
@Controller
public class HomeController {
@RequestMapping(value = "/test")
public String Test(){
return "index";
}
}
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Handles all requests into the application -->
<servlet>
<servlet-name>springmvc1</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Maps all /app requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springmvc1</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
And my springmvc1-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--
- DispatcherServlet application context for PetClinic's web tier.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">
<context:component-scan base-package="com.example.web"/>
<!--
- The BeanNameViewResolver is used to pick up the visits view name (below).
- It has the order property set to 2, which means that this will
- be the first view resolver to be used after the delegating content
- negotiating view resolver.
-->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" p:order="1"/>
<!--
- This bean configures the 'prefix' and 'suffix' properties of
- InternalResourceViewResolver, which resolves logical view names
- returned by Controllers. For example, a logical view name of "vets"
- will be mapped to "/WEB-INF/jsp/vets.jsp".
-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" p:order="2"/>
</beans>
I am getting the error:
HTTP Status 404 - Servlet springmvc1 is not available
type Status report
message Servlet springmvc1 is not available
description The requested resource (Servlet springmvc1 is not available) is not available.
What could be the problem?
Apache Tomcat/6.0.24
Here is the output that the server is giving:
Feb 9, 2010 11:14:03 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_17\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;E:\Program Files\CodeSmith\v4.1\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;E:\Program Files\QuickTime\QTSystem\;E:\Program Files\TortoiseSVN\bin;C:\Documents and Settings\Administrator\My Documents\Downloads\nant-0.85-rc4-bin\nant-0.85-rc4;C:\Program Files\CodeSmith\v5.1\;%JAVA_HOME%\bin;%M2%;e:\program files\jetbrains\intellij idea 9.0.1\jre\jre\bin
Feb 9, 2010 11:14:03 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 377 ms
Feb 9, 2010 11:14:03 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 9, 2010 11:14:03 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor ROOT.xml
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Feb 9, 2010 11:14:03 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory host-manager
Feb 9, 2010 11:14:04 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory manager
Feb 9, 2010 11:14:04 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Feb 9, 2010 11:14:04 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Feb 9, 2010 11:14:04 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
Feb 9, 2010 11:14:04 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 623 ms
Connected to server
Update tomcat log
It seems the tomcat log file is not updated immediatly, I guess it gets dumped very few minutes?
Below is the problem:
Feb 9, 2010 11:14:03 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1484)
at org.apache.catalina.loader.WebappClassLoader.loa开发者_StackOverflow社区dClass(WebappClassLoader.java:1329)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
The string thing is, I have spring 3.0 rc3
in my 'external libraries' folder in IntelliJ. Also, if I go and type org.springframework.web.servlet.DispatcherServlet
intellisense does the auto-completion which I assume means the library is being picked up as being part of the project.
Servlet springmvc1 is not available
This boils down to that
HttpServlet springmvc1 = new DispatcherServlet();
has failed during server's startup.
Read the server startup logs for any info/warnings/errors/details related to this. My cents on ClassNotFoundException
s or NoClassDefFoundError
s which in turn indicate missing JAR's in the runtime classpath.
精彩评论