Having some issues while running the below code:
Web.xml
<web-app 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"
version="3.0">
<display-name>To do List</display-name>
<welcome-file-list>
<welcome-file>login.do</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
-------------- todoservlet.xml -------------
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.in28minutes" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/webjars/**" location="/webjars/"/>
</beans>
-------------- login.jsp -------------
<html>
<head>
<title>Login Page</title>
</head>
<body>
<p><font color="red">${errorMessage}</font></p>
<form action="login.do" method="POST">
Name : <input name="name" type="text" />
Password : <input name="password" type="password" />
<input type="submit" />
</form>
</body>
</html>
-------------- Controller -------------
package com.in28minutes.login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
#Controller
#SessionAttributes("name")
public class LoginController {
#Autowired
private LoginService loginService;
#RequestMapping(value = "/login", method = RequestMethod.GET)
public String showLoginPage() {
return "login";
}
#RequestMapping(value = "/login", method = RequestMethod.POST)
public String handleUserLogin(ModelMap model, #RequestParam String name,
#RequestParam String password) {
if (!loginService.validateUser(name, password)) {
model.put("errorMessage", "Invalid Credentials");
return "login";
}
model.put("name", name);
return "welcome";
}
}
-------------- getting error message -------------
URL: http://localhost:8080/in28Minutes27-springmvc/
------------browser error --------------
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/8.0.39
----------------- log on console ---------------------
TRACE 2016-12-20 12:14:32,152 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Bound request context to thread: org.apache.catalina.connector.RequestFacade#df024db
DEBUG 2016-12-20 12:14:32,153 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/in28Minutes27-springmvc/]
TRACE 2016-12-20 12:14:32,155 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#1a6fbdb3] in DispatcherServlet with name 'dispatcher'
DEBUG 2016-12-20 12:14:32,156 [http-nio-8080-exec-2] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /login.do
DEBUG 2016-12-20 12:14:32,156 [http-nio-8080-exec-2] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/login.do]
TRACE 2016-12-20 12:14:32,157 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping#24b1f9e9] in DispatcherServlet with name 'dispatcher'
TRACE 2016-12-20 12:14:32,158 [http-nio-8080-exec-2] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping - No handler mapping found for [/login.do]
TRACE 2016-12-20 12:14:32,158 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1f358bf7] in DispatcherServlet with name 'dispatcher'
TRACE 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - No handler mapping found for [/login.do]
WARN 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/in28Minutes27-springmvc/] in DispatcherServlet with name 'dispatcher'
TRACE 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade#df024db
DEBUG 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.servlet.DispatcherServlet - Successfully completed request
TRACE 2016-12-20 12:14:32,159 [http-nio-8080-exec-2] org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in WebApplicationContext for namespace 'dispatcher-servlet': ServletRequestHandledEvent: url=[/in28Minutes27-springmvc/]; client=[0:0:0:0:0:0:0:1]; method=[GET]; servlet=[dispatcher]; session=[null]; user=[null]; time=[23ms]; status=[OK]
I am not able to resolve this issues; any help is appreciated.
The problem in your web.xml file. You cannot use .do extension as a welcome file, It should be valid presentation file with extension i.e .html, .jsp etc
Replace below block of code in your web.xml file
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
Hope it will work for you.
More Details:
when you don't have any handler methods to handle that path. Add one. Or add a <welcome-file> to your deployment descriptor, ie. the web.xml.
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
assuming the index.jsp is at the root of the WAR, ie. outside WEB-INF.
Related
Jul 18, 2017 8:45:43 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/hello-servlet.xml] Jul 18, 2017 8:45:44 PM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet 'hello': initialization completed in 580 ms Jul 18, 2017 8:45:44 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/HelloWorld/faisal] in DispatcherServlet with name 'hello'
hello-servlet.xml
you need to load ApplicationContext.xml in web.xml file, you can use sample bellow code for adding ApplicationContext.xml in web.xml
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:ApplicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
First if you want to get any response from your controller with your method declared as VOID you don't go to get any response, your method is printing in console the string faisl. Then if you want to get the index page that prints "faisal" you need to declare the controller like this:
#Controller
public class MainClass {
#RequestMapping(value="/faisal", method=RequestMethod.GET)
public ModelAndView getIndex(){
return new ModelAndView("index", "msg", "Hello Faisal");
}
}
in your hello-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:ctx = "http://www.springframework.org/schema/context"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc = "http://www.springframework.org/schema/mvc"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<ctx:component-scan base-package="com.faisal"></ctx:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
now the InternalViewResolver is looking for your index.jsp view that you have declared under /WEB-INF/
In your index.jsp you can do the next to print the message that you has mapped to your view:
<body>
<h1>${msg}</h1>
</body>
${msg} is the key that you are passing in the controller the value is Hello faisal then if you open the url
/HelloWorld/faisal
in your view you should be able to see Hello Faisal
Regards,
I looked at everypost related with this problem and tried nearly all of them. I'm getting this error. I also have created an empty Spring Maven MVC project and duplicated view and controller and named them as example.jsp and ExampleController.java etc. Shortly, I can not get any respond from Tomcat. I do not know it has anything to do with it but I' also getting and error at the beginning of Console log.
Thanks in advance...
Console log beginning warning (I do not know it has an affect on this problem):
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpitterSpring' did not find a matching property.
Here is my actual part of error:
Tem 11, 2014 4:55:32 PM org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
INFO: Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
Tem 11, 2014 4:55:32 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'appServlet': initialization completed in 885 ms
Tem 11, 2014 4:55:32 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Tem 11, 2014 4:55:32 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Tem 11, 2014 4:55:32 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9260 ms
Tem 11, 2014 4:55:34 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/] in DispatcherServlet with name 'appServlet'
Tem 11, 2014 4:55:39 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/spitter/deneme] in DispatcherServlet with name 'appServlet'
Tem 11, 2014 4:55:45 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/deneme] in DispatcherServlet with name 'appServlet'
Tem 11, 2014 4:55:52 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/spitter/deneme] in DispatcherServlet with name 'appServlet'
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/application-config.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Here is my servlet-context.xml file
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/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">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.ex.spitter.mvc" />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>
Here is my com.ex.spitter.mvc -> HomeController:
package com.ex.spitter.mvc;
import java.util.Map;
import javax.inject.Inject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.ex.spitter.service.SpitterService;
#Controller
public class HomeController {
private SpitterService spitterService;
#Inject
public HomeController(SpitterService spitterService) {
this.spitterService = spitterService;
}
#RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET)
public String showHomePage(Map<String, Object> model) {
model.put("spittles", spitterService.getRecentSpittles(spittlesPerPage));
return "home";
}
// <start id="spittlesPerPage"/>
public static final int DEFAULT_SPITTLES_PER_PAGE = 25;
private int spittlesPerPage = DEFAULT_SPITTLES_PER_PAGE;
public void setSpittlesPerPage(int spittlesPerPage) {
this.spittlesPerPage = spittlesPerPage;
}
public int getSpittlesPerPage() {
return spittlesPerPage;
}
// <end id="spittlesPerPage"/>
}
The problem was not solved but I changed my workspace and try to do it copy the codes. Besides, I will try to use a different version of Tomcat or install a Jboss
This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 5 years ago.
In setting up a Spring app (packaged as a WAR and hosted via Tomcat) I'm getting a 404 and the following error when I try to visit 'localhost:8080':
4479 [http-bio-8080-exec-1] WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/pages/index.html] in DispatcherServlet with name 'spring'
There is most definitely a /WEB-INF/pages/index.html file.
Here's my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
<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>
Additionally, here's my spring-servlet.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.company.app.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value= "/WEB-INF/pages/"/>
<property name="suffix" value=".html"/>
</bean>
</beans>
And the get method from my controller:
package com.company.app.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class SplashController {
#RequestMapping(value="/", method=RequestMethod.GET)
public String index() {
return "index";
}
}
So, what's wrong with my configuration?
Additionally: I'd like to include my console output from Spring's initial setup, maybe it will provide a clue or two as to what is missing:
0 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
92 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Sun Jan 26 16:16:57 EST 2014]; root of context hierarchy
147 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
776 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.company.app.controller.SplashController.index()
1547 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Root mapping to handler 'splashController'
1771 [localhost-startStop-1] INFO org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1770 ms
Jan 26, 2014 4:16:59 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
1809 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'spring': initialization started
1813 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Sun Jan 26 16:16:59 EST 2014]; parent: Root WebApplicationContext
1817 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
1947 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.company.app.controller.SplashController.index()
2164 [localhost-startStop-1] INFO org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Root mapping to handler 'splashController'
2205 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'spring': initialization completed in 396 ms
For whatever reason, changing the servlet-mapping portion of my web.xml to this solved the problem:
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I use Spring 3.2.3 release. Try this configuration:
Correct web.xml:
<servlet-mapping>
<servlet-name>Spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
Correct Spring-servlet.xml:
<context:component-scan base-package="your.package.controller"/>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean id="internalViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp"/>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
Correct mapping annotacion:
#RequestMapping(value="/index", method=RequestMethod.GET)
And create index.jsp file.
I also faced the same problem when a friend of mine suggest me to check for the package declaration.
After I knew for which package the definition of the controller request mapping and context:component-scan base-package to check for I saw it was not the same and after giving it the proper package name it started to work.
Check for the following snippet in your Spring config file
<context:component-scan base-package="your package name" >
I set up a OpenEntityManagerInViewFilter,but it always close session before writting to the database.here is my code ,please help me.Thank you .
<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>panshi</display-name>
<context-param>
<description>服务器的参数!</description>
<param-name>webAppRootKey</param-name>
<param-value>webRoot.root</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/*-config.xml
</param-value>
</context-param>
<context-param>
<description>日志的参数。</description>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
<!--
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/picshow/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/CSS/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/images/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
-->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<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>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<filter>
<filter-name>httpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>httpMethodFilter</filter-name>
<servlet-name>spring</servlet-name>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<!-- Displays a stack trace -->
<location>/WEB-INF/jsp/uncaughtException.jsp</location>
</error-page>
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>entityManagerFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>entityManagerFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>entityManagerFilter</filter-name>
<url-pattern>*.json</url-pattern>
</filter-mapping>
<!--
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class> org.springframework.orm.hibernate4.support.OpenSessionInViewFilter </filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.json</url-pattern>
</filter-mapping>
-->
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
</web-app>
JPA setting
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" 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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<context:component-scan base-package="cn.hballSoft.domain" />
<context:component-scan base-package="cn.hballSoft.security.domain" />
<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<!-- 这里多部分文件上传处理控制器 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000" />
</bean>
<!-- JPA EntityManagerFactory -->
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
<!-- JPA primary EntityManagerFactory entityManagerFactory-->
<bean id="entityManagerFactory" lazy-init="true"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceUnitName="ServerPU" p:jpaVendorAdapter-ref="jpaVendorAdapter"
p:jpaDialect-ref="jpaDialect" p:dataSource-ref="dataSource" />
<bean id="sessionFactory" factory-bean="entityManagerFactory"
factory-method="getSessionFactory">
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="departmentDao" class="cn.hballSoft.domain.dao.ImageDao"/>
<bean id="userDAO" class="cn.hballSoft.security.domain.UserDAO"/>
<bean id="roleDAO" class="cn.hballSoft.security.domain.RoleDAO"/>
<bean id="resourceDAO" class="cn.hballSoft.security.domain.ResourceDAO">
<qualifier value="resourceDAO"/>
</bean>
</beans>
persistence
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="ServerPU"
transaction-type="RESOURCE_LOCAL">
<!-- RESOURCE_LOCAL -->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!-- <class>cn.hballSoft.domain.Category</class>-->
<class>cn.hballSoft.security.domain.Resource</class>
<class>cn.hballSoft.security.domain.Role</class>
<class>cn.hballSoft.security.domain.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.showsql" value="true" />
<property name="hibernate.cache.use_second_level_cache"
value="false" />
<property name="hibernate.search.default.directory_provider"
value="org.hibernate.search.store.FSDirectoryProvider" />
<property name="hibernate.search.default.indexBase" value="d:/indexes" />
</properties>
</persistence-unit>
</persistence>
****DAO******
#Repository
#Transactional
public class ResourceDAO {
public static final String TYPE = "type";
#PersistenceContext
private EntityManager entityManager;
#Transactional
public void save(Resource entity) {
EntityManagerHelper.log("saving Resource instance", Level.INFO, null);
try {
entityManager.persist(entity);
EntityManagerHelper.log("save successful", Level.INFO, null);
} catch (RuntimeException re) {
EntityManagerHelper.log("save failed", Level.ERROR, re);
throw re;
}
}
}
*********method in the controller
#Transactional
#RequestMapping(value="/admin/manage/resource.json",method = RequestMethod.POST)
#ResponseBody
public LinkedHashMap<String, Object> createResource(#RequestBody Resource resource){
Resource res = new Resource(resource.getResourceString());
res.setDescn(resource.getDescn());
res.setMethod(resource.getMethod());
res.setType(resource.getType());
res.setPriority(resource.getPriority());
resourceDAO.save(res);
if(!res.getId().isEmpty()){
return buildMessageResult(true,"成功建立资源"+res.getId());}
else{
return buildMessageResult(true,"建立资源失败!");
}
}
****debug console output **************
09-04 17:59:32 DEBUG RequestMappingHandlerMapping:220 - Looking up handler method for path /admin/manage/resource.json
09-04 17:59:32 DEBUG RequestMappingHandlerMapping:264 - Found 1 matching mapping(s) for [/admin/manage/resource.json] : [{[/admin/manage/resource.json],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}]
09-04 17:59:32 DEBUG HandlerMethod:135 - Method [initBinder] returned [null]
09-04 17:59:32 DEBUG HandlerMethod:129 - Invoking [createResource] method with arguments [cn.hballSoft.security.domain.Resource#56ad4264]
09-04 17:59:32 INFO ServerPU:60 - saving Resource instance
09-04 17:59:32 DEBUG TransactionSynchronizationManager:140 - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#1a08777c] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#529e0c79] bound to thread [http-8080-2]
09-04 17:59:32 DEBUG AbstractSaveEventListener:130 - Generated identifier: 40288ae840e869000140e869a3f90000, using strategy: org.hibernate.id.UUIDHexGenerator
09-04 17:59:32 INFO ServerPU:60 - save successful
09-04 17:59:32 DEBUG HandlerMethod:135 - Method [createResource] returned [{Success=true, Message=成功建立资源40288ae840e869000140e869a3f90000}]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.ModelAndViewMethodReturnValueHandler#e58ff51] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.method.annotation.ModelMethodProcessor#2b39d891] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.ViewMethodReturnValueHandler#6b6b4e30] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor#59fcadd3] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.CallableMethodReturnValueHandler#31ccbefe] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.DeferredResultMethodReturnValueHandler#53e64a3b] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.AsyncTaskMethodReturnValueHandler#70f87478] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.method.annotation.ModelAttributeMethodProcessor#f74f6ef] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG HandlerMethodReturnValueHandlerComposite:78 - Testing if return value handler [org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor#47ffccd6] supports [java.util.LinkedHashMap<java.lang.String, java.lang.Object>]
09-04 17:59:32 DEBUG RequestResponseBodyMethodProcessor:150 - Written [{Success=true, Message=成功建立资源40288ae840e869000140e869a3f90000}] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter#34a8a271]
09-04 17:59:32 DEBUG DispatcherServlet:999 - Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling
09-04 17:59:32 DEBUG DispatcherServlet:1028 - Cleared thread-bound request context: FirewalledRequest[ org.apache.catalina.connector.RequestFacade#40545646]
09-04 17:59:32 DEBUG DispatcherServlet:966 - Successfully completed request
09-04 17:59:32 DEBUG XmlWebApplicationContext:332 - Publishing event in WebApplicationContext for namespace 'spring-servlet': ServletRequestHandledEvent: url=[/panshi/admin/manage/resource.json]; client=[127.0.0.1]; method=[POST]; servlet=[spring]; session=[1AC287B1EBE796642F17B9AB4F9B6D8A]; user=[null]; time=[96ms]; status=[OK]
09-04 17:59:32 DEBUG XmlWebApplicationContext:332 - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/panshi/admin/manage/resource.json]; client=[127.0.0.1]; method=[POST]; servlet=[spring]; session=[1AC287B1EBE796642F17B9AB4F9B6D8A]; user=[null]; time=[96ms]; status=[OK]
09-04 17:59:32 DEBUG TransactionSynchronizationManager:243 - Removed value [org.springframework.orm.jpa.EntityManagerHolder#1a08777c] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#529e0c79] from thread [http-8080-2]
09-04 17:59:32 DEBUG OpenEntityManagerInViewFilter:188 - Closing JPA EntityManager in OpenEntityManagerInViewFilter
09-04 17:59:32 DEBUG EntityManagerFactoryUtils:338 - Closing JPA EntityManager
09-04 18:09:59 DEBUG HttpSessionEventPublisher:83 - Publishing event: org.springframework.security.web.session.HttpSessionDestroyedEvent[source=org.apache.catalina.session.StandardSessionFacade#75f10df7]
09-04 18:09:59 DEBUG XmlWebApplicationContext:332 - Publishing event in Root WebApplicationContext: org.springframework.security.web.session.HttpSessionDestroyedEvent[source=org.apache.catalina.session.StandardSessionFacade#75f10df7]
09-04 18:09:59 DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'org.springframework.security.core.session.SessionRegistryImpl#0'
09-04 18:09:59 DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'loggerListener'
In the testcase , it works fine and write into the database well.
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration("jpa-config.xml")
#TransactionConfiguration(transactionManager="transactionManager", defaultRollback=false)
#Transactional
public class TestJPA {
ApplicationContext ctx;
DataSource dataSource;
#BeforeTransaction
public void verifyInitialDatabaseState() {
ctx = new FileSystemXmlApplicationContext("E:/FBworkspace/panshi/WebContent/WEB-INF/spring/jpa-config.xml");
dataSource = (DataSource)ctx.getBean("dataSource");
}
#Before
public void setUpTestDataWithinTransaction() {
// set up test data within the transaction
}
#Test
// overrides the class-level defaultRollback setting
#Rollback(false)
public void modifyDatabaseWithinTransaction() {
Resource res = new Resource("TEset REsource");
ResourceDAO resDao = (ResourceDAO)ctx.getBean("resourceDAO");
resDao.save(res);
}
#After
public void tearDownWithinTransaction() {
// execute "tear down" logic within the transaction
}
#AfterTransaction
public void verifyFinalDatabaseState() {
// logic to verify the final state after transaction has rolled back
}
}
************output with test *************
09-04 18:44:05 DEBUG EntityManagerFactoryRegistry:66 - Registering EntityManagerFactory: ServerPU
09-04 18:44:05 WARN EntityManagerFactoryRegistry:80 - HHH000436: Entity manager factory name (ServerPU) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
09-04 18:44:05 INFO ServerPU:60 - saving Resource instance
09-04 18:44:05 DEBUG TransactionSynchronizationManager:140 - Retrieved value [org.springframework.orm.jpa.EntityManagerHolder#4b5a142f] for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#6e3404f] bound to thread [main]
[org.springframework.transaction.support.DefaultTransactionStatus#54eeabe8]; rollback [false]
09-04 18:44:05 DEBUG JpaTransactionManager:923 - Triggering beforeCommit synchronization
09-04 18:44:05 DEBUG JpaTransactionManager:936 - Triggering beforeCompletion synchronization
09-04 18:44:05 DEBUG JpaTransactionManager:753 - Initiating transaction commit
09-04 18:44:05 DEBUG JpaTransactionManager:508 - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl#62c37f31]
09-04 18:44:05 DEBUG AbstractTransactionImpl:173 - committing
09-04 18:44:05 DEBUG JdbcTransaction:113 - committed JDBC Connection
09-04 18:44:05 DEBUG JdbcTransaction:126 - re-enabling autocommit
09-04 18:44:05 DEBUG DirtiesContextTestExecutionListener:107 - After test method: context [[TestContext#2f8bbc98 testClass = TestJPA, testInstance = cn.hballSoft.test.TestJPA#6ba7508a, testMethod = modifyDatabaseWithinTransaction#TestJPA, testException = [null], mergedContextConfiguration = [MergedContextConfiguration#3598cb3d testClass = TestJPA, locations = '{classpath:/cn/hballSoft/test/jpa-config.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]], class dirties context [false], class mode [null], method dirties context [false].
09-04 18:44:05 INFO GenericApplicationContext:1042 - Closing org.springframework.context.support.GenericApplicationContext#4cf7c31d: startup date [Wed Sep 04 18:43:59 CST 2013]; root of context hierarchy
09-04 18:44:05 DEBUG GenericApplicationContext:332 - Publishing event in org.springframework.context.support.GenericApplicationContext#4cf7c31d: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.support.GenericApplicationContext#4cf7c31d: startup date [Wed Sep 04 18:43:59 CST 2013]; root of context hierarchy]
09-04 18:44:05 DEBUG DefaultListableBeanFactory:246 - Returning cached instance of singleton bean 'lifecycleProcessor'
09-04 18:44:05 INFO DefaultListableBeanFactory:444 - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#62770d2e: defining beans
09-04 18:44:05 DEBUG DisposableBeanAdapter:226 - Invoking destroy() on bean with name 'entityManagerFactory'
09-04 18:44:05 INFO LocalContainerEntityManagerFactoryBean:441 - Closing JPA EntityManagerFactory for persistence unit 'ServerPU'
09-04 18:44:05 DEBUG SessionFactoryImpl:1369 - HHH000031: Closing
09-04 18:44:05 DEBUG EntityManagerFactoryRegistry:108 - Remove: name=ServerPU
09-04 18:44:05 DEBUG DisposableBeanAdapter:302 - Invoking destroy method 'close' on bean with name 'dataSource'
I know what happen.
I have multiple *-config.xml
all of them have
<context:annotation-config />
<context:component-scan base-package="cn.hballSoft.domain" />
<context:component-scan base-package="cn.hballSoft.security.domain" />
maybe it cause duplicate load transaction config.
keep single and slove the problem.
I'm having a strange problem with Spring MVC. I have a simple controller like this:
#Controller
#RequestMapping("admin")
public class AdminController {
#RequestMapping(value = "", method = RequestMethod.GET)
public String home() {
return "home";
}
When I run my server and access the url: localhost/admin I get a 404 error. The view home.jsp exists and should be rendered. When I check my spring event log this is what shows up:
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/admin]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /admin
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Returning handler method [public java.lang.String be.roots.buildinginspector.web.controller.AdminController.home()]
DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'adminController'
DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/admin] is: -1
DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'home'; URL [home]] in DispatcherServlet with name 'appServlet'
DEBUG: org.springframework.web.servlet.view.JstlView - Added model object 'domainOfExpertise' of type [be.roots.buildinginspector.business.model.DomainOfExpertise] to request in view with name 'home'
DEBUG: org.springframework.web.servlet.view.JstlView - Added model object 'org.springframework.validation.BindingResult.domainOfExpertise' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'home'
DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [home] in InternalResourceView 'home'
DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/home]
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /home
DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Did not find handler method for [/home]
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/home] in DispatcherServlet with name 'appServlet'
Everything is handled correctly but instead of just showing the view, the DispatcherServlet makes a new GET request to the url of the requested view name.
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring/config-core-business.xml
classpath*:/spring/config-app-security.xml
</param-value>
</context-param>
<!-- Spring Security filter -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring/appServlet/config-core-web.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Relevant spring context parts (config-core-web.xml):
<resources mapping="/resources/**" location="../../../resources" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/"/>
<beans:property name="suffix" value=".jsp"/>
</beans:bean>
#Controller
#RequestMapping("admin")
public class AdminController {
#RequestMapping(method = RequestMethod.GET)
public String home() {
return "home";
}
remove 'value' property of #RequestMapping for home() function.
After all it turned out this was a tomcat-related issue. For some reason when I recreated the configuration in my IDE the error was resolved. Thanks for your help.
I think this is servlet mapping problem in web.xml. Change it in web.xml to /admin addreses only. Perhaps now you have:
<url-pattern>*</url-pattern>
change it to:
<url-pattern>/admin/*</url-pattern>
The request mapping annotation defined over your methode restrict your controller to responds to requests starting with "/admin/home".
I would apply the following modifications :
#Controller
#RequestMapping("/admin")
public class AdminController {
#RequestMapping(method = RequestMethod.GET)
public String home() {
return "home";
}
}
Try this:
#RequestMapping(value = "admin",
method = {RequestMethod.GET, RequestMethod.POST })