I'm trying to setup and learn how to develop web applications with Spring MVC. I've been trying to follow a number of tutorials, but my application doesn't seem to want to work.
Enviro: Eclipse, m2e-wtp, spring, the whole shebang
Context root is BidApp.
I have one controller:
#Controller
public class AuctionController {
#RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
My web.xml in WEB-INF:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>BidApp</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.*</url-pattern>
</servlet-mapping>
</web-app>
And my spring-servlet.xml also in WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Scans within the base package of the application for #Components to configure as beans -->
<!-- #Controller, #Service, #Configuration, etc. -->
<context:component-scan base-package="com.bidapp.controllers" />
<!-- Enables the Spring MVC #Controller programming model -->
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
My I start the application and navigate to http://localhost:8080/BidApp/hello, it gives me a 404. Are my xml files in the wrong place or am I missing some configuration parameter? Is there a good place I can look at all the available parameters for configuring a spring application. The spring framework reference, unless I'm reading it wrong, isn't helping.
Edit:
Tomcat logs:
Nov 18, 2012 10:07:35 PM 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\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\php\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\MATLAB\R2010b\runtime\win64;C:\Program Files\MATLAB\R2010b\bin;C:\Users\Soto\Desktop\android-sdk-windows\tools;C:\Program Files (x86)\Common Files\Teleca Shared;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseHg\;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\MinGW\bin;C:\Program Files\nodejs\;C:\Ruby193\bin;C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;C:\Users\Soto\Desktop\android-sdk-windows\tools;C:\MinGW\bin;C:\Users\Soto\AppData\Roaming\npm\;C:\apache-maven-3.0.4\bin;C:\Program Files\Java\jdk1.7.0_02\bin;;.
Nov 18, 2012 10:07:35 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:BidApp' did not find a matching property.
Nov 18, 2012 10:07:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Nov 18, 2012 10:07:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Nov 18, 2012 10:07:35 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 594 ms
Nov 18, 2012 10:07:36 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Nov 18, 2012 10:07:36 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.22
Nov 18, 2012 10:07:36 PM org.apache.catalina.core.StandardContext checkUnusualURLPattern
INFO: Suspicious url pattern: "*.*" in context [/BidApp] - see section SRV.11.2 of the Servlet specification
Nov 18, 2012 10:07:36 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Nov 18, 2012 10:07:36 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Nov 18, 2012 10:07:36 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun Nov 18 22:07:36 EST 2012]; root of context hierarchy
Nov 18, 2012 10:07:36 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
Nov 18, 2012 10:07:36 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#6ad89088: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
Nov 18, 2012 10:07:37 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 739 ms
Nov 18, 2012 10:07:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Nov 18, 2012 10:07:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Nov 18, 2012 10:07:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1395 ms
You must use the url pattern like this
<url-pattern>/</url-pattern>
When you add <mvc:annotation-driven /> to your config, it replaces the default set of handler mappings and handler adapters, and those defaults were the ones that handled the old-style controllers.
i think you should understand the difference between component-scan and annotation-config. If you use scan then you do not need to use config.
Difference between <context:annotation-config> vs <context:component-scan>
Please do execute with your old code with removing the <mvc:annotation-driven />
(In general)/ will be working even without mvcdefault servlethandler
The dispatcher has an invalid mapping. Only 1 wildcard is accepted.
So change the dispatcher matching url to something like /*
So /*.do or /*.htm *.html but not /*.jsp as tomcat already maps the .jsps
If you want some REST urls, may I suggest using UrlRewriteFilter? It is really simple to use and can be used in closely the same way the apache rewrite filter is used.
Changing the url-pattern to <url-pattern>/</url-pattern> was not enough. In my spring-servlet.xml file I was missing a few elements:
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- This tag allows for mapping the DispatcherServlet to "/" (all extensions etc)-->
<mvc:default-servlet-handler/>
<!-- Enables many annotations and searches for #Controller annotated methods etc.. -->
<context:annotation-config />
Once these were added, the appropriate Controller was found (based on annotations) and it was executed at the proper URI starting at /.
Related
I am trying my hands on JAVA Spring MVC by writing a hello world code. I browsed a lot for it and I am trying to run it but I am not able to do that. Here is the following code:
HelloWeb-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.mvc" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HelloController.java
package com.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;
#Controller
#RequestMapping("/hello")
public class HelloController{
#RequestMapping(method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
WebContent/WEB-INF/jsp/hello.jsp
<%# page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
Following is the screenshot of the libraries used:
enter image description here
Everything seems fine with the code with no errors but when I run this on the server then it prompts to HTTP Status: 404 error with description "the requested resource is not available".Kindly seek me some way out of this.
I am getting the following error in the server console:
SEVERE: Servlet /SpringBlog threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:142)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Mar 07, 2016 2:25:01 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Mar 07, 2016 2:25:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'HelloWeb'
Mar 07, 2016 2:25:01 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'HelloWeb': initialization started
Mar 07, 2016 2:25:01 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'HelloWeb-servlet': startup date [Mon Mar 07 14:25:01 COT 2016]; root of context hierarchy
Mar 07, 2016 2:25:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB- INF/HelloWeb-servlet.xml]
Mar 07, 2016 2:25:02 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello] onto handler 'helloController'
Mar 07, 2016 2:25:02 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello.*] onto handler 'helloController'
Mar 07, 2016 2:25:02 PM org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping registerHandler
INFO: Mapped URL path [/hello/] onto handler 'helloController'
Mar 07, 2016 2:25:02 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'HelloWeb': initialization completed in 817 ms
Mar 07, 2016 2:25:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 07, 2016 2:25:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 07, 2016 2:25:02 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9007 ms
Ok this is always a problem for spring beginners, there could be tons of similar problems out there, but every time I type this issue, I always end up reading indirect solutions which I cannot understand, just like what the title said, I cannot resolve views(jsp) inside my WEB-INF/views folder, if i map the page using the file name.
Update: I've been searching extensively with a noHandlerFound/NoMapping Found for a URI problem, I just learned that the controller class name will be resolved by ControllerClassNameHandlerMapping removing the controller and lowercasing the non-controller name and it will be used as the url,
but I CANT still get to load my very simple page in start-up, and no matter where I search there are always tutorials that gives the same example, it does not work. please I need help here.. :(
ProductsHomeController.java (Controller class)
#Controller
public class ProductsHomeController{
#RequestMapping(value = "/productsHome", method = RequestMethod.GET)
public ModelAndView welcome() {
return new ModelAndView("productsHome");
}
xml configuration (XML configuration for MVC annotation and InternalResourceViewResolver)
<mvc:annotation-driven />
<context:component-scan base-package="edu.controllers" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-service.xml
/WEB-INF/applicationContext-repository.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener- class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Everytime I run this very simple web application on start,
The servlet resolves the view and display the content of the page by this URL
http://localhost:8080/ProductsHome/
but when I refresh the page, it results into a 404 error
and I need to manually type the file name of the jsp to resolve the view
http://localhost:8080/ProductsHome/productsHome
This is the kind of code I always see in the tutorials I'm reading especially spring-recipe book, but I cannot make it work the way it was said in the book, I expect that on the first start-up the dispatcher-servlet will resolve the views and displaying the page with this URL below
how can I make this work? any help would be greatly appreciated.
http://localhost:8080/ProductsHome/productsHome/home
here is the server log I get so far, I'm currently searching what I need to add to eclipse to show any error
Sep 04, 2014 11:37:09 AM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.30 using APR version 1.4.8.
Sep 04, 2014 11:37:09 AM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Sep 04, 2014 11:37:09 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:OnlineStudentRegistration' did not find a matching property.
Sep 04, 2014 11:37:09 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:Spring.MVC' did not find a matching property.
Sep 04, 2014 11:37:10 AM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized (OpenSSL 1.0.1g 7 Apr 2014)
Sep 04, 2014 11:37:10 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-apr-8080"]
Sep 04, 2014 11:37:10 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-apr-8009"]
Sep 04, 2014 11:37:10 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1875 ms
Sep 04, 2014 11:37:10 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 04, 2014 11:37:10 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.9
Sep 04, 2014 11:37:11 AM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [133] milliseconds.
Sep 04, 2014 11:37:14 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Sep 04, 2014 11:37:14 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Sep 04, 2014 11:37:14 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Sep 04, 2014 11:37:14 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Thu Sep 04 11:37:14 PDT 2014]; root of context hierarchy
Sep 04, 2014 11:37:15 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Sep 04, 2014 11:37:16 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.osr.controllers.StudentLoginController.student()
Sep 04, 2014 11:37:16 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/addStudent],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.osr.controllers.StudentLoginController.studentLogin(com.osr.domain.Student,org.springframework.validation.BindingResult)
Sep 04, 2014 11:37:17 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 2180 ms
Sep 04, 2014 11:37:21 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Sep 04, 2014 11:37:21 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Sep 04, 2014 11:37:22 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Sep 04, 2014 11:37:23 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-apr-8080"]
Sep 04, 2014 11:37:23 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
Sep 04, 2014 11:37:23 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 13063 ms
I thing the controller should be
#Controller
#RequestMapping(value = "/welcome")
public class WelcomeController {
#RequestMapping(method = RequestMethod.GET)
public ModelAndView welcome() {
return new ModelAndView("productsHome");
}
put the welcome-file-list in web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
in the file index.jsp , file index.jsp in the WEB-INF directory
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<% response.sendRedirect("welcome"); %>
change the servlet-mapping
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
make sure that productsHome.jsp is in the /WEB-INF/views/ directory
The problem is with the servlet mapping.
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I realize this question has been asked countless times, but none of the solutions appear to be working for my situation.
I have a basic Spring-WS app I'm putting together with a single servlet context. I can see that both the #Component annotated class and the properties file are both getting picked up on startup as shown by the logs below. However, my #Value annotated String is coming back as null.
Does anyone see anything wrong with the way I've set this up? Please feel free to ask for any additional information I may have left out.
Going forward, what are the best methods I can use to investigate issues like this I encounter in the future?
directmail-manager-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.xxx.direct.mailserver"/>
<context:property-placeholder location="classpath:manager.properties"/>
<sws:annotation-driven/>
<sws:dynamic-wsdl id="manager" portTypeName="EcwDirect"
locationUri="/mailerManagerService/" targetNamespace="http://obfuscated.com/direct/definitions">
<sws:xsd location="/WEB-INF/mailManagerRequest.xsd" />
</sws:dynamic-wsdl>
</beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
version="3.0"
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_3_0.xsd">
<display-name>xxxxxxxxx</display-name>
<servlet>
<servlet-name>directmail-manager</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>directmail-manager</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
manager.properties:
mailserver.url="localhost"
My annotated class:
package com.xxx.direct.mailserver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
#Component
public class TelnetMailServerUserController implements MailServerUserController {
#Autowired
#Value("${mailserver.url}")
String mailserverUrl;
#Override
public void addUser(String username, String password) {
System.out.println("server URL:" + mailserverUrl);
}
}
class that uses this class:
#Service
public class MailManagerService {
//TODO: craft and return response
public void registerNewUser(List<Element> usersToAdd) {
MailServerUserController userController = new TelnetMailServerUserController();
//TODO: add users fo realz
for(Element user : usersToAdd) {
String emailAddress = user.getChildText("emailAddress", MailManagerEndpoint.NAMESPACE);
String password = user.getChildText("password", MailManagerEndpoint.NAMESPACE);
//TODO: log this:
System.out.println("user " + emailAddress + " added");
userController.addUser(emailAddress, password);
//TODO: add to database
}
}
}
logs:
Apr 23, 2014 11:54:41 AM com.springsource.tcserver.security.PropertyDecoder <init>
INFO: tc Runtime property decoder using memory-based key
Apr 23, 2014 11:54:42 AM com.springsource.tcserver.security.PropertyDecoder <init>
INFO: tcServer Runtime property decoder has been initialized in 261 ms
Apr 23, 2014 11:54:42 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Apr 23, 2014 11:54:42 AM com.springsource.tcserver.serviceability.rmi.JmxSocketListener init
INFO: Started up JMX registry on 127.0.0.1:6969 in 128 ms
Apr 23, 2014 11:54:42 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 959 ms
Apr 23, 2014 11:54:42 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 23, 2014 11:54:42 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: VMware vFabric tc Runtime 2.9.3.RELEASE/7.0.42.A.RELEASE
Apr 23, 2014 11:54:42 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\springsource\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\conf\Catalina\localhost\ROOT.xml
Apr 23, 2014 11:54:42 AM org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:mail-server-manager' did not find a matching property.
Apr 23, 2014 11:54:44 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Apr 23, 2014 11:54:44 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\springsource\vfabric-tc-server-developer-2.9.3.RELEASE\base-instance\webapps\manager
Apr 23, 2014 11:54:44 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Apr 23, 2014 11:54:44 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1319 ms
Apr 23, 2014 11:54:44 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'directmail-manager'
Apr 23, 2014 11:54:44 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'directmail-manager': initialization started
Apr 23, 2014 11:54:44 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'directmail-manager-servlet': startup date [Wed Apr 23 11:54:44 EDT 2014]; root of context hierarchy
Apr 23, 2014 11:54:44 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/directmail-manager-servlet.xml]
Apr 23, 2014 11:54:44 AM org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
INFO: Loading properties file from class path resource [manager.properties]
Apr 23, 2014 11:54:45 AM org.springframework.ws.soap.addressing.server.AbstractAddressingEndpointMapping afterPropertiesSet
INFO: Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
Apr 23, 2014 11:54:45 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#7c0f6d9: defining beans [mailManagerEndpoint,mailManagerService,telnetMailServerUserController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping#0,org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping#0,org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping#0,org.springframework.ws.server.endpoint.adapter.method.dom.DomPayloadMethodProcessor#0,org.springframework.ws.server.endpoint.adapter.method.SourcePayloadMethodProcessor#0,org.springframework.ws.server.endpoint.adapter.method.jaxb.XmlRootElementPayloadMethodProcessor#0,org.springframework.ws.server.endpoint.adapter.method.jaxb.JaxbElementPayloadMethodProcessor#0,org.springframework.ws.server.endpoint.adapter.method.dom.JDomPayloadMethodProcessor#0,org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter#0,org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver#0,org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver#0,org.springframework.xml.xsd.SimpleXsdSchema#0,manager,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Apr 23, 2014 11:54:45 AM org.springframework.ws.soap.saaj.SaajSoapMessageFactory afterPropertiesSet
INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
Apr 23, 2014 11:54:45 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'directmail-manager': initialization completed in 1012 ms
user test added
server URL:null
You aren't using a Spring managed bean. You are creating an object yourself.
MailServerUserController userController = new TelnetMailServerUserController();
In this case, Spring is not involved in processing the #Value annotated field (or anything else for that matter).
Instead, get the bean from the context, inject it.
#Autowired
private MailServerUserController userController;
I am not able to find the cause why my destroy-method is not getting called when my application gets shut down in case of the tomcat stops.
I have a web application and the spring context is getting loaded through ContextLoaderListener in web.xml like below:
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:appContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
below is a Employee bean in my application:
Employee.class
public class Employee {
String eName;
long eSal;
public String getEName() {
return eName;
}
public void setEName(String name) {
eName = name;
}
public long getESal() {
return eSal;
}
public void setESal(long sal) {
eSal = sal;
}
public void init() {
System.out.println("Initiaizing...");
System.out.println("eName: " + eName + " - eSal: " + eSal);
}
public void close() {
System.out.println("Destroying...");
}
}
and the bean is defined in my application context file like below:
appContext.xml
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
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">
<beans:bean id="employee" class="com.test.Employee" init-method="init" destroy-method="close">
<beans:property name="eName" value="sandip" />
<beans:property name="eSal" value="80000" />
</beans:bean>
</beans:beans>
Tomcat console logs:
May 12, 2014 11:28:46 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\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jre7\bin\client;C:\Program Files\Java\jre7\bin;C:\Program Files\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Lenovo\Access Connections\;D:\Project\maven-2.0.7\bin;D:\Software Backup\apache-ant-1.7.0\bin;C:\Program Files\Java\jdk1.6.0_20\bin;D:\Project\OBD3\1.5;D:\Software Backup\CVS;D:\Project\UNIX\UnxUtils\usr\local\wbin;C:\Program Files\QuickTime\QTSystem\;D:\Personal\MongoDB\MongoDB_work\mongodb\bin;D:\Software Installed\MariaDB 5.5\bin;C:\Program Files\Git\bin
May 12, 2014 11:28:46 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:testSpringBeanDestroy' did not find a matching property.
May 12, 2014 11:28:46 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8093
May 12, 2014 11:28:46 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 419 ms
May 12, 2014 11:28:46 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 12, 2014 11:28:46 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
May 12, 2014 11:28:46 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\Project\Workspace_new\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\testSpringBeanDestroy\WEB-INF\lib\servlet.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
May 12, 2014 11:28:46 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Initiaizing...
eName: sandip - eSal: 80000
May 12, 2014 11:28:47 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8093
May 12, 2014 11:28:47 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8011
May 12, 2014 11:28:47 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/20 config=null
May 12, 2014 11:28:47 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 768 ms
When I start my tomcat I can see that my init method is getting called but unfortunately when I stops the tomcat the close() i.e. the destroy method is not getting called.
I am using spring 3.1.2 distributions jars.
What am I doing wrong?
Thanks Andrei. +1 for you.
The problem was that I was not shutting down properly. Now after reading some docs I found that if I shuts down my tomcat gracefully either from the Tomcat Manager or using the shutdown scripts like(shutdwon.sh/shutdown.bat), My destroy method is getting called.
Kill -9 command will not work and also if trying to stop from eclipse, it is not working.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd"
id="WebApp_ID"
version="3.0">
<display-name>audiClave</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>rest.root</param-value>
</context-param>
<!-- Processes application requests -->
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet</servlet- class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/REST/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>base</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>base</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
base-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Scans within the base package of the application for #Components to configure as beans -->
<!-- #Controller, #Service, #Configuration, etc. -->
<context:component-scan base-package="com.audiClave.controllers" />
<!-- Enables the Spring MVC #Controller programming model -->
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Here is the BaseController:
package com.audiClave.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class BaseController {
#RequestMapping(value = "/index.html")
public ModelAndView home() {
System.out.println("BaseController: Passing through...");
return new ModelAndView("home");
// return "WEB-INF/views/home.jsp";
}
}
I call the tomcat service with:
http://localhost:8080/audiClave/index.html
and this is from the console:
BaseController: Passing through...
appears in the console window but nothing else. Content returned states:
description The requested resource () is not available.
Contents of /WEB-INF/views/home.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Audiclave</title>
</head>
<body>
<h1>Hello world from audiClave!</h1>
</body>
</html>
The problem isn't in the file though because if I return
return new ModelAndView("xxxx");
It is the same result.
It does seem to be library related as it was working before I started changing the libraries (relating to JSTL and JSP) in my project. I don't know the sequence of the libraries I have changed. I must have ended up with something incompatible with tomcat 7.
There is nothing in the tomcat log that indicates a problem. This is the startup log:
01/06/2011 9:25:20 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\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Python26\Scripts;C:\Python26\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\90\DTS\Binn\;C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files\Java\jdk1.6.0_21\bin;%APPDATA%\Python\Scripts;C:\Program Files\Translate Toolkit;C:\Program Files\Gallio\bin
01/06/2011 9:25:20 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:audiClave' did not find a matching property.
01/06/2011 9:25:20 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
01/06/2011 9:25:20 AM org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
01/06/2011 9:25:20 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 336 ms
01/06/2011 9:25:20 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
01/06/2011 9:25:20 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
01/06/2011 9:25:22 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'rest'
01/06/2011 9:25:22 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'rest': initialization started
01/06/2011 9:25:22 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'rest-servlet': startup date [Wed Jun 01 09:25:22 EST 2011]; root of context hierarchy
01/06/2011 9:25:22 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/rest-servlet.xml]
01/06/2011 9:25:22 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#62610b: defining beans [baseController,restController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,beanNameResolver,RemedyXml]; root of factory hierarchy
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/index.html] onto handler 'baseController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}] onto handler 'restController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}.*] onto handler 'restController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}/] onto handler 'restController'
01/06/2011 9:25:22 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'rest': initialization completed in 359 ms
01/06/2011 9:25:22 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'base'
01/06/2011 9:25:22 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'base': initialization started
01/06/2011 9:25:22 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'base-servlet': startup date [Wed Jun 01 09:25:22 EST 2011]; root of context hierarchy
01/06/2011 9:25:22 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/base-servlet.xml]
01/06/2011 9:25:22 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#848ecc: defining beans [baseController,restController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0]; root of factory hierarchy
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/index.html] onto handler 'baseController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}] onto handler 'restController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}.*] onto handler 'restController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/REST/remedies/{language}/] onto handler 'restController'
01/06/2011 9:25:23 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'base': initialization completed in 297 ms
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
01/06/2011 9:25:23 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8080"]
01/06/2011 9:25:23 AM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
01/06/2011 9:25:23 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2490 ms
As per Biju's recommendation here is the log from after baseController returns the modelAndView:
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'home'
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'home'; URL [/WEB-INF/views/home.jsp]] in DispatcherServlet with name 'base'
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/home.jsp] in InternalResourceView 'home'
2011-06-01 11:32:59,218 ["http-bio-8080"-exec-11] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
Register a ViewResolver in the Spring configuration along these lines:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
Now you should be able to return "home" from your controller's requestmapped method and it should correctly get resolved to "/WEB-INF/views/home.jsp" page.
You're probably missing a dependent library (which is why it fails regardless of what JSP file you specify) and your Spring context is erroring out when it tries to create something. Look carefully in catalina.out for a java.lang.NoClassDefFoundError and see if you can figure out which class it is missing.
The problem is that home.jsp does not exist in the
.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\audiClave\WEB-INF\views
directory even though in eclipse it is showing. Wasn't able to see that until I got the logging working properly.
Stopping the server, cleaning, and then republishing seems to have fixed it.