DispatcherServlet doesn't appear to be processing the ModelAndView response - java

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.

Related

On running code on server it prompts to 404 page

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

Cannot Resolve Views inside WEB-INF/ folders using the jsp filename as RequestMapping value

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>

Spring #Value Annotation Not Resolving

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;

Bad configuration on Spring-mvc Maven Hibernate, can't access http no mapping

i'm having some issues. I'm building an application with Spring Tool Suit, consist of SpringMVC Maven and Hibernate. I think i have all my coding ok or close to be good despite i'm noob with spring.
Here i put 2 screens of my project:
http://i.stack.imgur.com/AzhOd.png
http://i.stack.imgur.com/fBRId.png
Here i put what i think the files that are involved on the issue
aplication-config.mxl:
<?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"
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">
<context:component-scan base-package="org.springframework.samples.service"/>
</beans>
GeneralController.java:
package controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import form.Egg;
import service.EggService;
#Controller
//#RequestMapping("/ChickenTest/**")
public class GeneralController {
#Autowired
EggService eggService;
#RequestMapping(value="/index")
public ModelAndView index(){
ModelAndView mav = new ModelAndView();
return mav;
}
//Index of Egg webpage
#RequestMapping(value="/Egg/indexEgg")
public ModelAndView indexEgg(){
ModelAndView mav = new ModelAndView();
return mav;
}
//Action of adding an Egg
#RequestMapping(value="/Egg/addEgg", method = RequestMethod.POST)
public ModelAndView addEgg(#ModelAttribute Egg egg){
ModelAndView mav = new ModelAndView("/index");
Egg eggAux = egg;
eggService.addEgg(eggAux);
return mav;
}
//View list of eggs
#RequestMapping(value="/Egg/viewEggs", method = RequestMethod.POST)
public ModelAndView viewEggs(){
ModelAndView mav = new ModelAndView("/index");
mav.getModelMap().addAttribute("eggList", eggService.viewEggs());
return null;
}
#RequestMapping(value="/Chicken/indexChicken")
ModelAndView indexChicken(){
ModelAndView mav = new ModelAndView();
return mav;
}
#RequestMapping(value="/Farm/indexFarm")
ModelAndView indexFarm(){
ModelAndView mav = new ModelAndView();
return mav;
}
}
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ChickenTest</display-name>
<!--
- Location of the XML file that defines the root application context.
- Applied by ContextLoaderListener.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/application-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
mvc-config.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.xsd
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">
<context:component-scan
base-package="org.springframework.samples.web"/>
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Here is what the console outputs when i try to enter one of my jsp:
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.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ChickenTest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) # ChickenTest >>>
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # ChickenTest ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # ChickenTest ---
[INFO] Compiling 16 source files to C:\Java\workspace2\ChickenTest\target\classes
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:run (default-cli) # ChickenTest <<<
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:run (default-cli) # ChickenTest ---
[INFO] Running war on http://localhost:8080/ChickenTest
[INFO] Using existing Tomcat server configuration at C:\Java\workspace2\ChickenTest\target\tomcat
Nov 08, 2013 12:31:45 AM org.apache.catalina.startup.Embedded start
INFO: Starting tomcat server
Nov 08, 2013 12:31:45 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
Nov 08, 2013 12:31:45 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Nov 08, 2013 12:31:45 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Nov 08, 2013 12:31:45 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Fri Nov 08 00:31:45 ART 2013]; root of context hierarchy
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring/application-config.xml]
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#767ae5: 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.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Nov 08, 2013 12:31:45 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 245 ms
Nov 08, 2013 12:31:45 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcherServlet'
Nov 08, 2013 12:31:45 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcherServlet': initialization started
Nov 08, 2013 12:31:45 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcherServlet-servlet': startup date [Fri Nov 08 00:31:45 ART 2013]; parent: Root WebApplicationContext
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-config.xml]
Nov 08, 2013 12:31:45 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#132299b: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#767ae5
Nov 08, 2013 12:31:46 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcherServlet': initialization completed in 384 ms
Nov 08, 2013 12:31:46 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Nov 08, 2013 12:31:46 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Finally this is what the explorer shows when i try to enter this url http:// localhost:8080/ChickenTest/index.jsp
HTTP Status 404 - /ChickenTest/index.jsp
type Status report
message /ChickenTest/index.jsp
description The requested resource (/ChickenTest/index.jsp) is not available.
Apache Tomcat/6.0.29
Thanks for reading! i will be in touch if you need something more!
update 1:
Hi there again, i applied this solution:
First, your #Controller class is in
package controller;
so your DispatcherServlet config needs to have a component-scan on that package. So change yours to
<context:component-scan base-package="controller"/>
So that the <mvc:annotation-driven> gets applied and your #Controller class is added as a handler.
Now even if you do this, you still don't seem to have a handler method for the path
/ChickenTest/index.jsp
You'll want to either add a <welcome-file> to your web.xml and an index.jsp file in your /webapps folder or add a #RequestMapping handler method that can handler /index.jsp.
but now the console tells me that the #Autowire on GeneralController.class is not working.
This is my new error:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'generalController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.chicken.service.EggService com.chicken.controller.GeneralController.eggService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.chicken.service.EggService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
First, your #Controller class is in
package controller;
so your DispatcherServlet config needs to have a component-scan on that package. So change yours to
<context:component-scan base-package="controller"/>
So that the <mvc:annotation-driven> gets applied and your #Controller class is added as a handler.
Now even if you do this, you still don't seem to have a handler method for the path
/ChickenTest/index.jsp
You'll want to either add a <welcome-file> to your web.xml and an index.jsp file in your /webapps folder or add a #RequestMapping handler method that can handler /index.jsp.
The Exception you now get is (broken down)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'generalController':
Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: com.chicken.service.EggService com.chicken.controller.GeneralController.eggService;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.chicken.service.EggService] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
So, the component scan couldn't create a bean for GeneralController because the Spring context could not find an EggService bean which it needs to inject into it. The only possible reason for this is that there is no EggService bean in your context. Either you haven't declared in as a <bean> or your component-scan isn't scanning the package where your EggService class is declared as a #Component.

What's wrong with my Spring MVC configuration?

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

Categories

Resources