java ee spring error - java

I am facing a problem, It doesn't redirect to a jsp(HTTP 404) from the controller although I entered correctly a valid url address that can be treated by the controller. Here is my web.xml, the controller and what the debugger shows me.
I entered http://localhost:8080/AccessControl/produits.aspx
<?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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ApplicationAccessControl</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-beans.xml</param-value>
</context-param>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.aspx</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>default.aspx</welcome-file>
</welcome-file-list>
</web-app>
AgentAdministrativeController.java in the controller package
package controller;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import dao.AgentAdministrative;
import services.AgentAdministrativeMetier;
import services.SessionBean;
public class AgentAdministrativeController {
#Autowired
AgentAdministrativeMetier services;
#Autowired
private SessionBean sessionBean;
#RequestMapping(value={"/connnexiontrait","/default"})
public String verifier(Model model,#RequestParam String username,#RequestParam String motdepasse,#RequestParam int labo){
Long t;
String arg1;
t=services.verifaccess(username, motdepasse, labo);
if (t.intValue()==0)
{
arg1="Nom d'utilisateur ou mot de passe ou numero de laboratoire sont incorrectes ,veuillez les ressaisir " ;
model.addAttribute("erreurs", arg1);
System.out.println("succes");
return "connexion";
}
else
{
System.out.println("succes");
return "produits";
}
}
#RequestMapping(value={"/produits"})
public String verifie(Model model)
{
return "produits";
}
}
This is what Debugger shows me.
mars 29, 2015 8:32:12 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
AVERTISSEMENT: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:AccessControl' did not find a matching property.
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server version: Apache Tomcat/8.0.20
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server built: Feb 15 2015 18:10:42 UTC
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Server number: 8.0.20.0
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: OS Name: Linux
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: OS Version: 3.16.0-23-generic
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Architecture: i386
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Java Home: /usr/lib/jvm/java-7-openjdk-i386/jre
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: JVM Version: 1.7.0_75-b13
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: JVM Vendor: Oracle Corporation
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: CATALINA_BASE: /home/sami/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: CATALINA_HOME: /home/sami/Téléchargements/apache-tomcat-8.0.20
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dcatalina.base=/home/sami/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dcatalina.home=/home/sami/Téléchargements/apache-tomcat-8.0.20
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dwtp.deploy=/home/sami/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Djava.endorsed.dirs=/home/sami/Téléchargements/apache-tomcat-8.0.20/endorsed
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.VersionLoggerListener log
INFOS: Command line argument: -Dfile.encoding=UTF-8
mars 29, 2015 8:32:12 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFOS: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386:/usr/lib/jvm/java-7-openjdk-i386/jre/../lib/i386:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/client:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386::/usr/java/packages/lib/i386:/usr/lib/i386-linux-gnu/jni:/lib/i386-linux-gnu:/usr/lib/i386-linux-gnu:/usr/lib/jni:/lib:/usr/lib
mars 29, 2015 8:32:12 AM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["http-nio-8080"]
mars 29, 2015 8:32:12 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFOS: Using a shared selector for servlet write/read
mars 29, 2015 8:32:12 AM org.apache.coyote.AbstractProtocol init
INFOS: Initializing ProtocolHandler ["ajp-nio-8009"]
mars 29, 2015 8:32:12 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFOS: Using a shared selector for servlet write/read
mars 29, 2015 8:32:12 AM org.apache.catalina.startup.Catalina load
INFOS: Initialization processed in 885 ms
mars 29, 2015 8:32:12 AM org.apache.catalina.core.StandardService startInternal
INFOS: Démarrage du service Catalina
mars 29, 2015 8:32:12 AM org.apache.catalina.core.StandardEngine startInternal
INFOS: Starting Servlet Engine: Apache Tomcat/8.0.20
mars 29, 2015 8:32:14 AM org.apache.catalina.core.ApplicationContext log
INFOS: 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.
hibernate framework !!
mars 29, 2015 8:32:15 AM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["http-nio-8080"]
mars 29, 2015 8:32:15 AM org.apache.coyote.AbstractProtocol start
INFOS: Starting ProtocolHandler ["ajp-nio-8009"]
mars 29, 2015 8:32:15 AM org.apache.catalina.startup.Catalina start
INFOS: Server startup in 2937 ms
mars 29, 2015 8:32:58 AM org.apache.catalina.core.ApplicationContext log
INFOS: Initializing Spring FrameworkServlet 'action'
This is application-servlet-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:context="http://www.springframework.org/schema/context"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.xsd">
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

There are couple of issues with your controller.
Your controller is missing #Controller annotation.
Your application-servlet-config.xml does not have spring mvc elements, hence your controller is not even being picked up when server starts. You can controller mapping in your logs, if its picked up.
So try using the below application-servlet-config.xml instead and see. I would also suggest seeing a spring mvc tutorial, if this does not resolve it.
<?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:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<context:annotation-config />
<context:component-scan base-package="your.controller.package" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>

Related

How to fix Http Status 404 Not found?

I've just started with Spring framework, currently learning the spring MVC the configuration is just too complicated xD , anyway everytime i try to run the application on the server it gives me this page instead of main-menu.jsp page.
I've tried to add the #RequestMapping("/") to the method in my controller calss and the method should return a String as u can see in the code below
HompePage.java
#Controller
public class HomePage {
#RequestMapping("/")
public String showPage() {
return "main-menu";
}
main-menu.jsp page
<!DOCTYPE html>
<html>
<body>
<h2>Spring MVC Demo - Home Page</h2>
</body>
</html>
spring-mvc-demo-servelet.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/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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Step 3: Add support for component scanning -->
<context:component-scan base-package="com.Ayoub.springdemo.mvc" />
<!-- Step 4: Add support for conversion, formatting and validation support -->
<mvc:annotation-driven/>
<!-- Step 5: Define Spring MVC view resolver -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
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>SpringMVC</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I've got Http status 404 - Not found
Logs
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name: Apache Tomcat/9.0.24
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Aug 14 2019 21:16:42 UTC
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 9.0.24.0
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Linux
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 4.18.0-25-generic
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /usr/lib/jvm/java-12-oracle
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 12.0.1+12
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /home/ayoub/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /home/ayoub/Desktop/apache-tomcat-9.0.24
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/ayoub/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/home/ayoub/Desktop/apache-tomcat-9.0.24
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/ayoub/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Sep 05, 2019 3:37:32 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Sep 05, 2019 3:37:32 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:/usr/lib64:/lib64:/lib:/usr/lib]
Sep 05, 2019 3:37:34 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Sep 05, 2019 3:37:34 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Sep 05, 2019 3:37:34 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [3,226] milliseconds
Sep 05, 2019 3:37:34 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Sep 05, 2019 3:37:34 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.24]
Sep 05, 2019 3:37:35 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Sep 05, 2019 3:37:35 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Sep 05, 2019 3:37:35 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [1,524] milliseconds
your web.xml should be like this you have to give servelt name
<?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>SpringMVC</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
#Controller
public class HomePage {
#RequestMapping("/main-menu")
public String showPage() {
return "main-menu";
}

Basic Spring Web MVC Application using annotation

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"

No mapping found for HTTP request with URI [/offers/] in DispatcherServlet with name 'offers'

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.

No error in apache but I get a 404 error

I have been at this for a day now and cannot understand why it is not working. I followed a tutorial, read the spring documentation and still do not understand, even better there are on errors to go off of.
Mar 19, 2015 6:42: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:Spring with JSP' did not find a matching property.
Mar 19, 2015 6:42: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:JavaSpringMVCTake2' did not find a matching property.
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.17
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jan 9 2015 15:58:59 UTC
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.17.0
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Mac OS X
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.10.2
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: x86_64
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JAVA_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_31-b13
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /Users/DrewJocham/Documents/caveOfprograming/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /apache-tomcat-8.0.17
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/Users/DrewJocham/Documents/caveOfprograming/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/apache-tomcat-8.0.17
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/Users/DrewJocham/Documents/caveOfprograming/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/apache-tomcat-8.0.17/endorsed
Mar 19, 2015 6:42:04 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Mar 19, 2015 6:42: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: /Users/DrewJocham/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Mar 19, 2015 6:42:04 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 19, 2015 6:42:05 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 19, 2015 6:42:05 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Mar 19, 2015 6:42:05 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 19, 2015 6:42:05 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2855 ms
Mar 19, 2015 6:42:05 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 19, 2015 6:42:05 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.17
Mar 19, 2015 6:42: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.
Mar 19, 2015 6:42:06 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [223] milliseconds.
Mar 19, 2015 6:42:08 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Mar 19, 2015 6:42:08 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'offers'
Mar 19, 2015 6:42:08 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'offers': initialization started
Mar 19, 2015 6:42:08 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'offers-servlet': startup date [Thu Mar 19 18:42:08 CET 2015]; root of context hierarchy
Mar 19, 2015 6:42:08 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/offers-servlet.xml]
Mar 19, 2015 6:42:10 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.learnspring.controller.OffersController.showHome()
Mar 19, 2015 6:42:10 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'offers-servlet': startup date [Thu Mar 19 18:42:08 CET 2015]; root of context hierarchy
Mar 19, 2015 6:42:10 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for #ControllerAdvice: WebApplicationContext for namespace 'offers-servlet': startup date [Thu Mar 19 18:42:08 CET 2015]; root of context hierarchy
Mar 19, 2015 6:42:10 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'offers': initialization completed in 2159 ms
Mar 19, 2015 6:42:12 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Mar 19, 2015 6:42:12 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Mar 19, 2015 6:42:12 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Mar 19, 2015 6:42:12 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6971 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>JavaSpringMVCTake2</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></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>
</web-app>
controller Servlet
<?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>
<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>
controller class
package com.learnspring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class OffersController {
#RequestMapping("/")
public String showHome() {
return "home";
}
}
home.jsp
<%# 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 World from JSP...
</body>
</html>
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>
So your web.xml configuration need below configuration, add belows.
<?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>
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;
}
}
Final notes:
Use Spring webmvc jar. checkpom.xml all you need is this.
Add to offers-servlet.xml . Check below notes for
-Don't use run on server inside eclipse and make the request to http://localhost:8080/offers/ from a browser.
The caveat to overriding the "/" Servlet mapping is that the
RequestDispatcher for the default Servlet must be retrieved by name
rather than by path. The DefaultServletHttpRequestHandler will attempt
to auto-detect the default Servlet for the container at startup time,
using a list of known names for most of the major Servlet containers
(including Tomcat, Jetty, GlassFish, JBoss, Resin, WebLogic, and
WebSphere).
Resource

Spring MVC - No mapping found for HTTP request with URI [/webstore/] in DispatcherServlet with name 'DefaultServlet'

I'm following along with the book "Spring MVC Beginner's Guide", and I'm running into what appear to be request mapping problems.
I have seen and tried the following solutions in other, similar Stack Overflow questions:
changing the "url-pattern" from / to /*
changing both the url-pattern and the parameter of the RequestMapping annotation to "/welcome"
adding <mvc:default-servlet-handler/> to DefaultServlet-servlet.xml
changing the url-pattern to "/WEB-INF/jsp/*"
I've got the following code:
Directory structure:
HomeController.java
package webstore;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HomeController {
#RequestMapping(value="/")
public String welcome(Model model) {
model.addAttribute("greeting", "Welcome to Web Store!");
model.addAttribute("tagline", "The one and only amazing webstore!");
return "welcome";
}
}
welcome.jsp
<%# taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<title>Welcome</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1>${greeting} </h1>
<p>${tagline} </p>
</div>
</div>
</section>
</body>
</html>
DefaultServlet-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/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.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.packt.webstore" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<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">
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DefaultServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Here is the entire server log when I start up the server in my IDE (Spring Tool Suite):
Feb 12, 2015 12:32:07 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:webstore' did not find a matching property.
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jan 28 2015 15:51:10 UTC
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.59.0
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Mac OS X
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.9.2
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: x86_64
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.7.0_60-b19
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /Users/richiethomas/Documents/workspace-sts-3.6.3.SR1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /Users/richiethomas/Downloads/apache-tomcat-7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/Users/richiethomas/Documents/workspace-sts-3.6.3.SR1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/Users/richiethomas/Downloads/apache-tomcat-7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/Users/richiethomas/Documents/workspace-sts-3.6.3.SR1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/Users/richiethomas/Downloads/apache-tomcat-7.0.59/endorsed
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Feb 12, 2015 12:32:07 AM 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/richiethomas/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Feb 12, 2015 12:32:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Feb 12, 2015 12:32:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 536 ms
Feb 12, 2015 12:32:07 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 12, 2015 12:32:07 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.deploy.WebXml setVersion
WARNING: Unknown version string [ 3.0]. Default version will be used.
Feb 12, 2015 12:32:08 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Feb 12, 2015 12:32:08 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 12, 2015 12:32:08 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 12, 2015 12:32:08 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1010 ms
Your problem seems to be with component scan,
you are scanning wrong package. Your controller lies in webstore package, so change in your servlet configuration:
<context:component-scan base-package="webstore" />
Or move your Controllers to com.packt.webstore package.
When your app is being deployed you should see in logs what url mappings have been registered, then you will know if this fix worked.
In web.xml Try changing
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
to
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/DefaultServlet-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Remove "value=" from the #RequestMapping(value="/") in the controller method.

Categories

Resources