I know there are millions of possible solutions to this, and I tried many of them, but still no benefit at all.
I am trying to map a basic controller to a url and returning a JSP view. Its showing HTTP Status 404 with description The requested resource is not available. Please help.
Controller
package controllers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class HomePageController {
#RequestMapping(value = "/twenty-eight/index", method = RequestMethod.GET)
public ModelAndView homePage(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse){
ModelAndView mav = new ModelAndView("HomePage");
System.out.println("Going to index page...");
return mav;
}
}
web.xml
<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 Web MVC Application</display-name>
<servlet>
<servlet-name>dispatcher-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher-servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
servlet-context.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">
<context:component-scan base-package="controllers" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
JSP View
<!DOCTYPE html>
<html>
<head>
<title>HTML5 Login</title>
<link rel="stylesheet" href="CSS/normalize.css">
<link rel="stylesheet" href="CSS/style.css">
</head>
<body>
<h1>Working Fine</h1>
</body>
</html>
Tomcat logs
Aug 02, 2015 7:16:04 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Twenty Eight' did not find a matching property.
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.21
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Mar 23 2015 14:11:21 UTC
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.21.0
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Linux
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 3.16.0-44-generic
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /usr/local/java/jdk1.8.0_40/jre
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_40-b26
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /home/kaustubh/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /var/local/apache-tomcat-8.0.21
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/kaustubh/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/var/local/apache-tomcat-8.0.21
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/kaustubh/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/var/local/apache-tomcat-8.0.21/endorsed
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Aug 02, 2015 7:16:04 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Aug 02, 2015 7:16:04 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Aug 02, 2015 7:16:04 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 02, 2015 7:16:04 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Aug 02, 2015 7:16:04 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Aug 02, 2015 7:16:04 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 989 ms
Aug 02, 2015 7:16:04 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 02, 2015 7:16:04 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.21
Aug 02, 2015 7:16:06 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Aug 02, 2015 7:16:06 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Aug 02, 2015 7:16:07 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher-servlet'
Aug 02, 2015 7:16:07 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher-servlet': initialization started
Aug 02, 2015 7:16:07 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet-servlet': startup date [Sun Aug 02 19:16:07 IST 2015]; root of context hierarchy
Aug 02, 2015 7:16:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/servlet-context.xml]
Aug 02, 2015 7:16:08 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFO: Mapped "{[/twenty-eight/index],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView controllers.HomePageController.homePage(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
Aug 02, 2015 7:16:09 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet-servlet': startup date [Sun Aug 02 19:16:07 IST 2015]; root of context hierarchy
Aug 02, 2015 7:16:09 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet-servlet': startup date [Sun Aug 02 19:16:07 IST 2015]; root of context hierarchy
Aug 02, 2015 7:16:09 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher-servlet': initialization completed in 1772 ms
Aug 02, 2015 7:16:09 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Aug 02, 2015 7:16:09 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Aug 02, 2015 7:16:09 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4680 ms
Project Structure
https://drive.google.com/open?id=0B2s3KIDgKxy8RlVqZmdneW9WV1U
Related
I'm aware there are a bunch of topics with same issues, but after 3 days researching I couldn't solve my problem.
If anyone spot the answer somewhere else, please feel free to mark this as duplicate and lead me there.
I'm trying to map a request in my Controller and then redirect to a subfolder under my default view folder. However, I'm getting a 404 error.
My 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>SIGCOM</display-name>
<servlet>
<servlet-name>springController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springController.xml</param-value>
</context-param>
<filter>
<filter-name>SpringFilter</filter-name>
<filter-class>br.com.sigcom.filter.SpringFilter</filter-class>
<init-param>
<param-name>requestEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SpringFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
<listener>
<listener-class>br.com.sigcom.listener.SpringListener</listener-class>
</listener>
-->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/WebContent/WEB-INF/views/errorHandling/errorPage.jsp</location>
</error-page>
<error-page>
<!-- Missing resource -->
<error-code>404</error-code>
<location>/WebContent/WEB-INF/views/errorHandling/error404.jsp</location>
</error-page>
</web-app>
My 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:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
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
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<context:component-scan base-package="br.com.sigcom.controller" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926" />
</beans>
As you see, my default views folder is WEB-INF/views. So far so good. I made a subfolder like this:
WEB-INF/
|-views/
|-admin/
|-default.jsp
In my Controller, I can't access WEB-INF/views/admin/default.jsp, for I get this 404 error.
My Controller:
package br.com.sigcom.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class SpringController {
#RequestMapping(value = {"", "/", "home", "default", "index"})
public String redirectDefaultPage() {
return "default";
}
#RequestMapping("admin")
public String redirectAdminPage() {
return "admin/default";
}
}
I tried a lot, searched a lot, however without success. I know this must be a simple detail, but I'm exhausted. Thank you in advance!
PS.: my console:
mai 02, 2017 9:36:23 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SIGCOM' did not find a matching property.
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server version: Apache Tomcat/8.0.43
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server built: Mar 28 2017 14:42:59 UTC
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server number: 8.0.43.0
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Name: Windows 8.1
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Version: 6.3
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Architecture: amd64
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Java Home: C:\Program Files (x86)\Java
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Version: 1.8.0_131-b11
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Vendor: Oracle Corporation
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_BASE: C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_HOME: C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.base=C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.home=C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dwtp.deploy=C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\wtpwebapps
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Djava.endorsed.dirs=C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\endorsed
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dfile.encoding=Cp1252
mai 02, 2017 9:36:23 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAÇÕES: 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 (x86)\Java\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/bin/server;C:/Program Files (x86)/Java/bin;C:/Program Files (x86)/Java/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\Program Files (x86)\Borland\Delphi7\Bin;C:\Program Files (x86)\Borland\Delphi7\Projects\Bpl\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;c:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\MySQL\MySQL Utilities 1.6\;C:\Arquivos de programas\Borland\Delphi7\Projects\Bpl;C:\morais_san\Development\Delphi\Repository\Components\JVCL3.33\jcl;C:\morais_san\Development\Java\Maven\apache-maven-3.5.0\bin;C:\morais_san\Development\Eclipse\eclipse-jee-neon-R-win32-x86_64\eclipse;;.
mai 02, 2017 9:36:23 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["http-nio-8080"]
mai 02, 2017 9:36:23 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
mai 02, 2017 9:36:23 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["ajp-nio-8009"]
mai 02, 2017 9:36:23 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
mai 02, 2017 9:36:23 PM org.apache.catalina.startup.Catalina load
INFORMAÇÕES: Initialization processed in 982 ms
mai 02, 2017 9:36:23 PM org.apache.catalina.core.StandardService startInternal
INFORMAÇÕES: Starting service Catalina
mai 02, 2017 9:36:23 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAÇÕES: Starting Servlet Engine: Apache Tomcat/8.0.43
mai 02, 2017 9:36:25 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
mai 02, 2017 9:36:26 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: No Spring WebApplicationInitializer types detected on classpath
mai 02, 2017 9:36:26 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: Initializing Spring FrameworkServlet 'springController'
mai 02, 2017 9:36:26 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFORMAÇÕES: FrameworkServlet 'springController': initialization started
mai 02, 2017 9:36:26 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFORMAÇÕES: Refreshing WebApplicationContext for namespace 'springController-servlet': startup date [Tue May 02 21:36:26 BRT 2017]; root of context hierarchy
mai 02, 2017 9:36:26 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFORMAÇÕES: Loading XML bean definitions from ServletContext resource [/WEB-INF/springController-servlet.xml]
mai 02, 2017 9:36:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFORMAÇÕES: Mapped "{[/search],methods=[GET]}" onto public java.lang.String br.com.sigcom.controller.SearchController.redirectSearchPage()
mai 02, 2017 9:36:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFORMAÇÕES: Mapped "{[/admin]}" onto public java.lang.String br.com.sigcom.controller.SpringController.redirectAdminPage()
mai 02, 2017 9:36:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFORMAÇÕES: Mapped "{[ || / || /home || /default || /index]}" onto public java.lang.String br.com.sigcom.controller.SpringController.redirectDefaultPage()
mai 02, 2017 9:36:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFORMAÇÕES: Looking for #ControllerAdvice: WebApplicationContext for namespace 'springController-servlet': startup date [Tue May 02 21:36:26 BRT 2017]; root of context hierarchy
mai 02, 2017 9:36:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFORMAÇÕES: Looking for #ControllerAdvice: WebApplicationContext for namespace 'springController-servlet': startup date [Tue May 02 21:36:26 BRT 2017]; root of context hierarchy
mai 02, 2017 9:36:28 PM org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
INFORMAÇÕES: Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
mai 02, 2017 9:36:28 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFORMAÇÕES: FrameworkServlet 'springController': initialization completed in 2250 ms
mai 02, 2017 9:36:28 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deploying web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\docs
mai 02, 2017 9:36:28 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deployment of web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\docs has finished in 35 ms
mai 02, 2017 9:36:28 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deploying web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\examples
mai 02, 2017 9:36:29 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: ContextListener: contextInitialized()
mai 02, 2017 9:36:29 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: SessionListener: contextInitialized()
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deployment of web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\examples has finished in 456 ms
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deploying web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\host-manager
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deployment of web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\host-manager has finished in 45 ms
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deploying web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\manager
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deployment of web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\manager has finished in 44 ms
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deploying web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\ROOT
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFORMAÇÕES: Deployment of web application directory C:\morais_san\Development\Tomcat\apache-tomcat-8.0.43\webapps\ROOT has finished in 32 ms
mai 02, 2017 9:36:29 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["http-nio-8080"]
mai 02, 2017 9:36:29 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["ajp-nio-8009"]
mai 02, 2017 9:36:29 PM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 5763 ms
mai 02, 2017 9:59:25 PM org.apache.catalina.core.StandardContext reload
INFORMAÇÕES: Reloading Context with name [/SIGCOM] has started
mai 02, 2017 9:59:25 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: Destroying Spring FrameworkServlet 'springController'
mai 02, 2017 9:59:25 PM org.springframework.web.context.support.XmlWebApplicationContext doClose
INFORMAÇÕES: Closing WebApplicationContext for namespace 'springController-servlet': startup date [Tue May 02 21:36:26 BRT 2017]; root of context hierarchy
mai 02, 2017 9:59:27 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
mai 02, 2017 9:59:27 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: No Spring WebApplicationInitializer types detected on classpath
mai 02, 2017 9:59:27 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: Initializing Spring FrameworkServlet 'springController'
mai 02, 2017 9:59:27 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFORMAÇÕES: FrameworkServlet 'springController': initialization started
mai 02, 2017 9:59:27 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFORMAÇÕES: Refreshing WebApplicationContext for namespace 'springController-servlet': startup date [Tue May 02 21:59:27 BRT 2017]; root of context hierarchy
mai 02, 2017 9:59:27 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFORMAÇÕES: Loading XML bean definitions from ServletContext resource [/WEB-INF/springController-servlet.xml]
mai 02, 2017 9:59:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFORMAÇÕES: Mapped "{[/search],methods=[GET]}" onto public java.lang.String br.com.sigcom.controller.SearchController.redirectSearchPage()
mai 02, 2017 9:59:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFORMAÇÕES: Mapped "{[/admin]}" onto public java.lang.String br.com.sigcom.controller.SpringController.redirectAdminPage()
mai 02, 2017 9:59:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping register
INFORMAÇÕES: Mapped "{[ || / || /home || /default || /index]}" onto public java.lang.String br.com.sigcom.controller.SpringController.redirectDefaultPage()
mai 02, 2017 9:59:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFORMAÇÕES: Looking for #ControllerAdvice: WebApplicationContext for namespace 'springController-servlet': startup date [Tue May 02 21:59:27 BRT 2017]; root of context hierarchy
mai 02, 2017 9:59:28 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFORMAÇÕES: Looking for #ControllerAdvice: WebApplicationContext for namespace 'springController-servlet': startup date [Tue May 02 21:59:27 BRT 2017]; root of context hierarchy
mai 02, 2017 9:59:28 PM org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
INFORMAÇÕES: Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
mai 02, 2017 9:59:28 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFORMAÇÕES: FrameworkServlet 'springController': initialization completed in 1456 ms
mai 02, 2017 9:59:28 PM org.apache.catalina.core.StandardContext reload
INFORMAÇÕES: Reloading Context with name [/SIGCOM] is completed
I've tried setup a project with the same setting you had except there is no filter, filter-mapping, error-page, listener in the web.xml and I'm able to access the access the URL without 404.
The controller is able to resolve the template as well.
Did you enter your URL correctly with the context path as well?
e.g. http://localhost:8080/SIGCOM/admin
I've create a new project with your code. But at last, i get the right thing. Maybe you can check you url like first floor says.
SOLVED. As you guys runned without filter, I've commented mine and worked. Now I know what to do. Appreciate your your help, guys!
My basic Spring MVC web application doesn't work. I created Simple Spring Web Maven Project and deleted unnecessary code to simplify it. Then, I added Controller implementation and annotated it like in book I have read recently. I deployed a sample application from book and an app I have just created. The sample app works properly - mine not. When i try to acces the URL ...localhost.../app-name/start/basic/show Tomcat Server shows 404 Error. There's my code:
BasicController in spring.app package
#Controller
#RequestMapping("/basic")
public class BasicController{
#RequestMapping("/show")
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
Map < String, String > modelData = new HashMap < String, String >();
modelData.put("message", "Hello World!");
return new ModelAndView("showMessage", modelData);
}
}
App/src/main/webapp/WEB-INF/mvc-config.xml file:
<?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">
<mvc:annotation-driven />
<context:component-scan base-package="spring.app"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
App/src/main/webapp/WEB-INF/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">
<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>/start/*</url-pattern>
</servlet-mapping>
</web-app>
showMessage.jsp in WEB-INF/view directory:
<!DOCTYPE html>
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="utf-8">
<title>Welcome</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
I was trying to solve this problem, but everything is implemented like in sample app so i don't know why it fails.
My traces, when i choose "run on server" and i have dployed only this app:
cze 29, 2015 6:44:27 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:App' did not find a matching property.
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.23
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: May 19 2015 14:58:38 UTC
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.23.0
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 8.1
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.3
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_45
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_45-b15
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:60768
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\wtpwebapps
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\endorsed
cze 29, 2015 6:44:27 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1250
cze 29, 2015 6:44:27 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
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\jre1.8.0_45\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_45/bin/server;C:/Program Files/Java/jre1.8.0_45/bin;C:/Program Files/Java/jre1.8.0_45/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\xampp\php;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin;C:\Users\Adrian\Desktop\eclipse;;.
cze 29, 2015 6:44:27 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8081"]
cze 29, 2015 6:44:28 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
cze 29, 2015 6:44:28 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8010"]
cze 29, 2015 6:44:28 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
cze 29, 2015 6:44:28 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1648 ms
cze 29, 2015 6:44:28 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
cze 29, 2015 6:44:28 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.23
cze 29, 2015 6:44:28 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [125] milliseconds.
cze 29, 2015 6:44:28 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\docs
cze 29, 2015 6:44:28 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\docs has finished in 63 ms
cze 29, 2015 6:44:28 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\examples
cze 29, 2015 6:44:29 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
cze 29, 2015 6:44:29 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
cze 29, 2015 6:44:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\examples has finished in 962 ms
cze 29, 2015 6:44:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\host-manager
cze 29, 2015 6:44:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\host-manager has finished in 78 ms
cze 29, 2015 6:44:29 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\manager
cze 29, 2015 6:44:30 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\manager has finished in 110 ms
cze 29, 2015 6:44:30 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\ROOT
cze 29, 2015 6:44:30 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Users\Adrian\Desktop\apache-tomcat-8.0.23-windows-x64\apache-tomcat-8.0.23\webapps\ROOT has finished in 47 ms
cze 29, 2015 6:44:30 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8081"]
cze 29, 2015 6:44:30 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8010"]
cze 29, 2015 6:44:30 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2149 ms
Ok, Let's say that I solve this problem by creating Spring MVC Project instead of Simple Spring Web Maven Project. Everything works, now.
According to your log
your app does not get deploy.I got a clue from your log
INFO: Deploying
when you read about INFO: Deploying
It does not say anything about your app which is "/App"
I am learning spring and am making an practice program. I am getting the following a 404 error when I run the program. I will post the whole console output at the end. I am trying to implement the DAO method and create new pages with controllers. I will post the code so you understand what i am trying to say:
url
http://localhost:8080/SpringMVCTest/
offers controller
#Controller
public class OffersController {
public OffersController() {
System.out.println("loaded OffersController");
}
/*
* private OffersService offersService;
*
* #Autowired public void setOffersService(OffersService offersService) {
* this.offersService = offersService; }
*/
#RequestMapping("/offers")
public ModelAndView showOffers() {
System.out.println("in offers");
ModelAndView mv = new ModelAndView("/offers");
return mv;
}
#RequestMapping("/createoffer")
public ModelAndView createOffer() {
System.out.println("in createoffer");
ModelAndView mv = new ModelAndView("/createoffer");
return mv;
}
}
offer.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:forEach var="offers" items="${offer}">
<p><c:out value= ${offers}></c:out></p>
<p />
</c:forEach>
</body>
</html>
home.jsp controller
package com.learnspring.web.config;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class HomeController {
#RequestMapping("/")
public ModelAndView showMessage() {
System.out.println("in controller");
ModelAndView mv = new ModelAndView("/home");
return mv;
}
}
home.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<p> Show current offers</p>
<p> Add a new offer</p>
</body>
</html>
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"
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>SpringMVCTest</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/offers-servlet.xml</param-value>
</context-param>
<!-- Database bean named offer and the DAO implementation -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/learnspring/web/config/dao-context.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:com/learnspring/web/config/dao-context.xml
classpath:com/learnspring/web/config/service-context.xml
</param-value>
</context-param>
<!-- Servlet for offers -->
<servlet>
<description></description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- MySQL configuration -->
<description>Spring Database</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/spring</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
service-context.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"
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-4.1.xsd">
<!-- handles OffersService.java -->
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.learnspring.service"></context:component-scan>
</beans>
OffersService.java
package com.learnspring.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.learnspring.DAO.Offer;
import com.learnspring.DAO.OfferDAO;
#Service("offersService")
public class OffersService {
private OfferDAO offersDAO;
#Autowired
public void setOffersDAO(OfferDAO offersDAO) {
this.offersDAO = offersDAO;
}
public List<Offer> getCurrent() {
return offersDAO.getOffers();
}
}
console output
Mar 29, 2015 7:31:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringMVCTest' did not find a matching property.
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.17
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jan 9 2015 15:58:59 UTC
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.17.0
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Mac OS X
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.10.2
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: x86_64
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_31-b13
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /apache-tomcat-8.0.17
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /apache-tomcat-8.0.17
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/apache-tomcat-8.0.17
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/apache-tomcat-8.0.17
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/apache-tomcat-8.0.17/webapps
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/apache-tomcat-8.0.17/endorsed
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Mar 29, 2015 7:31:59 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/DrewJocham/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Mar 29, 2015 7:31:59 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 29, 2015 7:31:59 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 29, 2015 7:31:59 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Mar 29, 2015 7:31:59 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 29, 2015 7:31:59 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1248 ms
Mar 29, 2015 7:31:59 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 29, 2015 7:31:59 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.17
Mar 29, 2015 7:32:01 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Mar 29, 2015 7:32:01 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Mar 29, 2015 7:32:01 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Mar 29, 2015 7:32:01 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Sun Mar 29 19:32:01 CEST 2015]; root of context hierarchy
Mar 29, 2015 7:32:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/learnspring/web/config/dao-context.xml]
Mar 29, 2015 7:32:02 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/learnspring/web/config/service-context.xml]
It loaded DAO
Mar 29, 2015 7:32:02 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 834 ms
Mar 29, 2015 7:32:02 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'offers'
Mar 29, 2015 7:32:02 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'offers': initialization started
Mar 29, 2015 7:32:02 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'offers-servlet': startup date [Sun Mar 29 19:32:02 CEST 2015]; parent: Root WebApplicationContext
Mar 29, 2015 7:32:02 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/offers-servlet.xml]
loaded OffersController
Mar 29, 2015 7:32:03 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/offers],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.learnspring.test.OffersController.showOffers()
Mar 29, 2015 7:32:03 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/createoffer],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.learnspring.test.OffersController.createOffer()
Mar 29, 2015 7:32:03 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'offers-servlet': startup date [Sun Mar 29 19:32:02 CEST 2015]; parent: Root WebApplicationContext
Mar 29, 2015 7:32:03 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'offers-servlet': startup date [Sun Mar 29 19:32:02 CEST 2015]; parent: Root WebApplicationContext
Mar 29, 2015 7:32:03 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'offers': initialization completed in 1053 ms
Mar 29, 2015 7:32:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/docs
Mar 29, 2015 7:32:03 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 29, 2015 7:32:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/docs has finished in 124 ms
Mar 29, 2015 7:32:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/examples
Mar 29, 2015 7:32:03 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Mar 29, 2015 7:32:03 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Mar 29, 2015 7:32:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/examples has finished in 297 ms
Mar 29, 2015 7:32:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/host-manager
Mar 29, 2015 7:32:04 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 29, 2015 7:32:04 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/host-manager has finished in 132 ms
Mar 29, 2015 7:32:04 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/manager
Mar 29, 2015 7:32:04 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 29, 2015 7:32:04 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/manager has finished in 97 ms
Mar 29, 2015 7:32:04 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/ROOT
Mar 29, 2015 7:32:04 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 29, 2015 7:32:04 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/ROOT has finished in 102 ms
Mar 29, 2015 7:32:04 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Mar 29, 2015 7:32:04 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Mar 29, 2015 7:32:04 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4440 ms
Mar 29, 2015 7:32:05 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVCTest/] in DispatcherServlet with name 'offers'
Mar 29, 2015 7:35:30 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVCTest/] in DispatcherServlet with name 'offers'
offers-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:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.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-4.1.xsd">
<context:component-scan base-package="com.learnspring.test">
</context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsps"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
You HomeController seems to be in com.learnspring.web.config and that is not being package scanned. I guess your OffersController is in the same package. Else you need to add that to package scanning as well. Hope this resolves the issue.So try changing the below
<context:component-scan base-package="com.learnspring.test">
</context:component-scan>
to
<context:component-scan base-package="com.learnspring.web.config">
</context:component-scan>
I have already had help with this program and got it to work. I then decided I would do it again my scratch to make sure I understood but I got the same issues. The hard part is the console is not printing out any errors.
console:
Mar 22, 2015 9:07:09 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:LearnSpringMVC' did not find a matching property.
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.17
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jan 9 2015 15:58:59 UTC
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.17.0
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Mac OS X
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.10.2
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: x86_64
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_31-b13
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /apache-tomcat-8.0.17
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /apache-tomcat-8.0.17
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/apache-tomcat-8.0.17
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/apache-tomcat-8.0.17
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/apache-tomcat-8.0.17/wtpwebapps
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/apache-tomcat-8.0.17/endorsed
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Mar 22, 2015 9:07:09 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/DrewJocham/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Mar 22, 2015 9:07:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 22, 2015 9:07:09 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 22, 2015 9:07:09 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Mar 22, 2015 9:07:09 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 22, 2015 9:07:09 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1890 ms
Mar 22, 2015 9:07:09 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 22, 2015 9:07:09 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.17
Mar 22, 2015 9:07:11 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Mar 22, 2015 9:07:12 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [216] milliseconds.
Mar 22, 2015 9:07:12 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/docs
Mar 22, 2015 9:07:12 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 22, 2015 9:07:12 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/docs has finished in 194 ms
Mar 22, 2015 9:07:12 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/examples
Mar 22, 2015 9:07:13 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Mar 22, 2015 9:07:13 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/examples has finished in 750 ms
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/host-manager
Mar 22, 2015 9:07:13 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/host-manager has finished in 164 ms
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/manager
Mar 22, 2015 9:07:13 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/manager has finished in 172 ms
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /apache-tomcat-8.0.17/webapps/ROOT
Mar 22, 2015 9:07:13 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /apache-tomcat-8.0.17/webapps/ROOT has finished in 147 ms
Mar 22, 2015 9:07:13 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Mar 22, 2015 9:07:13 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Mar 22, 2015 9:07:13 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4068 ms
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID"
version="3.1">
<display-name>SpringJSP</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:offers-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
home.jsp file
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Hello from JSP...
</body>
</html>
OffersController.java
package com.learnspring.controller;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
#Controller
#RequestMapping(value = "/")
public class OffersController {
#RequestMapping(method = RequestMethod.GET)
public ModelAndView homeGet(HttpServletRequest request) {
System.out.println("Check mapping");
ModelAndView model = new ModelAndView("home");
return model;
}
}
offers-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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.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-4.1.xsd">
<context:component-scan base-package="com.learnspring.controller"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>
<mvc:default-servlet-handler />
<bean
id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property
name="prefix"
value="/WEB-INF/jsps/"></property>
<property
name="suffix"
value=".jsp"></property>
</bean>
</beans>
I do not know why this keeps happening to me. Can anyone help out? I checked the working code line by line and it was correct and it still works.
your application context xml file name should be offers-servlet.xml in stead of offers.xml
I am learning spring and stuck on this error. I have clean the project, ran maven build which runs build success and refreshed the target but I have still had no luck. Here is the code:
error
Apr 21, 2015 8:49:30 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Spring_Project' did not find a matching property.
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.15
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Nov 2 2014 19:25:20 UTC
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.15.0
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Mac OS X
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.10.3
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: x86_64
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_31-b13
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /Users/DrewJocham/Documents/practice/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /Library/apache-tomcat-8.0.15
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/Users/DrewJocham/Documents/practice/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/Library/apache-tomcat-8.0.15
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/Users/DrewJocham/Documents/practice/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/Library/apache-tomcat-8.0.15/endorsed
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Apr 21, 2015 8:49:30 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/DrewJocham/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Apr 21, 2015 8:49:30 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Apr 21, 2015 8:49:30 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 21, 2015 8:49:30 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Apr 21, 2015 8:49:30 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 21, 2015 8:49:30 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1204 ms
Apr 21, 2015 8:49:30 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 21, 2015 8:49:30 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.15
Apr 21, 2015 8:49:32 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Apr 21, 2015 8:49:32 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Apr 21, 2015 8:49:32 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Apr 21, 2015 8:49:32 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue Apr 21 20:49:32 CEST 2015]; root of context hierarchy
Apr 21, 2015 8:49:32 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/learnspring/config/daoContext.xml]
Apr 21, 2015 8:49:33 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/learnspring/config/offersService.xml]
Apr 21, 2015 8:49:33 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 861 ms
Apr 21, 2015 8:49:33 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'offers'
Apr 21, 2015 8:49:33 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'offers': initialization started
Apr 21, 2015 8:49:33 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'offers-servlet': startup date [Tue Apr 21 20:49:33 CEST 2015]; parent: Root WebApplicationContext
Apr 21, 2015 8:49:33 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/offers-servlet.xml]
Apr 21, 2015 8:49:34 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'offers-servlet': startup date [Tue Apr 21 20:49:33 CEST 2015]; parent: Root WebApplicationContext
Apr 21, 2015 8:49:34 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'offers-servlet': startup date [Tue Apr 21 20:49:33 CEST 2015]; parent: Root WebApplicationContext
Apr 21, 2015 8:49:34 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'offers': initialization completed in 1209 ms
Apr 21, 2015 8:49:34 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Apr 21, 2015 8:49:34 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Apr 21, 2015 8:49:34 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4187 ms
Apr 21, 2015 8:49:35 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/offers/] in DispatcherServlet with name 'offers'
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"
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>Spring_Project</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>offers</description>
<display-name>offers</display-name>
<servlet-name>offers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<description>Database</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/Spring_Tutorial</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:com/learnspring/config/daoContext.xml
classpath:com/learnspring/config/offersService.xml
</param-value>
</context-param>
daoContext.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:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.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-4.1.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan
base-package="com.learnspring.datasource.DAO">
</context:component-scan>
<jee:jndi-lookup jndi-name="jdbc/Spring_Tutorial" id="dataSource"
expected-type="javax.sql.DataSource">
</jee:jndi-lookup>
</beans>
offersService.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"
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-4.1.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.learnspring.service">
</context:component-scan>
</beans>
OffersController.java
package com.learnspring.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.learnspring.datasource.DAO.Offer;
import com.learnspring.service.OffersService;
#Controller
public class OffersController {
private OffersService offersService;
//#Autowired
public void setOffersService(OffersService offersService) {
this.offersService = offersService;
}
#RequestMapping("/")
public String getHome(Model model) {
List<Offer> offers = offersService.getCurrent();
model.addAttribute("offers", offers);
return "home";
}
}
OffersService.java
package com.learnspring.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.learnspring.datasource.DAO.Offer;
import com.learnspring.datasource.DAO.OfferDAO;
#Service("offersService")
public class OffersService {
private OfferDAO offerDAO;
#Autowired
public void setOfferDAO(OfferDAO offerDAO) {
this.offerDAO = offerDAO;
}
public List<Offer> getCurrent() {
return offerDAO.getOffers();
}
}
It looks like you're trying to register your controller on web.xml by doing:
<servlet-mapping>
<servlet-name>offers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
In my opinion you don't need to do that. You can get away with just registering the RequestDispatcher and then as Patrick LC mentioned, have
<context:component-scan base-package="com.learnspring.controller">
take care of scanning your code for controllers to register. Then, it's a matter of setting the request mapping to whatever you want to use. Below I use home.spr, where spr stands for spring, but that's just a convention I use; the important thing is that whatever you choose needs to be declared on the web.xml as below:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.spr</url-pattern>
</servlet-mapping>
Then on your controller do:
#RequestMapping("/orders/home.spr")
public String getHome(Model model) {
List<Offer> offers = offersService.getCurrent();
model.addAttribute("offers", offers);
return "home";
}
Oh...and you might want to try spring.io, it's a bit simpler to work with.