I've got a spring project using tiles as UI framework. I wanted to provide a generic controller handling static html files (no dynamic content - so no custom controllers). The generic controller is org.springframework.web.servlet.mvc.UrlFilenameViewController. The whole thing works for if I put static content in .jsp extension files. As long as I try to put them in .html - I get 404 error and I want to figure out why.
web.xml:
<display-name>
lyricsBase
</display-name>
<servlet>
<servlet-name>lyricsBaseApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lyricsBaseApp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>list.html</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/jsp/404.jsp</location>
</error-page>
lyricsBaseApp-servlet.xml:
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="staticViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
<property name="prefix" value="t." />
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/list.html">jukeboxController</prop>
<prop key="/display.html">songController</prop>
<prop key="/static/about.html">staticViewController</prop>
</props>
</property>
</bean>
tiles.xml:
<definition name="t.base" template="/WEB-INF/tiles/base.jsp">
<put-attribute name="title" value="SomeTitle"/>
</definition>
<definition name="t.static/about" extends="t.base">
<put-attribute name="body" value="/WEB-INF/static/about.jsp"/>
<put-attribute name="title" expression="about"/>
</definition>
This is the URL I'm accessing the static page at: http://localhost:8084/lyricsBase/static/about.html
I've got both about.html and about.jsp files in the proper directory. If a
<put-attribute name="body" value="/WEB-INF/static/about.jsp"/>
to
<put-attribute name="body" value="/WEB-INF/static/about.html"/>
I start getting the warning in tomcat:
2013-02-16 18:21:45 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/lyricsBase/WEB-INF/static/about.html] in DispatcherServlet with name 'lyricsBaseApp'
Why?
I know this question was asked 2 years ago, but I encountered the same problem and maybe sometime someone else.
I think Tiles only supports JSP, Freemarker or Velocity. I could find a workaround. Define a static handler like so:
#Configuration
#EnableWebMvc
#ComponentScan(value = "com.xy"))
public class WebConfig extends WebMvcConfigurerAdapter {
#Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/lyricsBase/static/**")
.addResourceLocations("/WEB-INF/static/");
}
}
now you should be able to use your html template by tiles:
<put-attribute name="body" value="/lyricsBase/static/about.html"/>
Related
I am doing project on Spring MVC with html file as viewResolver. Already my project done in ftl (freemarker template) files as viewResolver perfectly. But I want to do conversion of all ftl files into html files. Hence I have tried hard for two days and do some configuration changes in view resolver like below, but nothing worked.
My original code in applicationContext.xml
<bean id="viewResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".ftl" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="exposeRequestAttributes" value="true" />
<property name="allowRequestOverride" value="false" />
<property name="exposeSessionAttributes" value="true" />
<property name="allowSessionOverride" value="false" />
<property name="exposePathVariables" value="true" />
<property name="requestContextAttribute" value="rc" />
</bean>
I have made some changes like below
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".html" />
</bean>
My DispatcherServlet configuration
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></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>
My html files are in "/WEB-INF/views/" folder. What changes I need to do to run the html files. Any alternate way also warmly welcome. Thanks in advance guys...
HTML pages meant for implementing static views, we have great feature in spring to render the static resources like html, css and images i.e.
<mvc:resources mapping="/static/**" location="/WEB-INF/static/" />
Similar question asked here SpringViewResolver for HTML views
================================ SOLUTION ========================================
Newly created Folder structure:
WEB-INF
`-static
|-html
`-index.html
Spring config:
<resources mapping="/static/**" location="/WEB-INF/static/" />
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="" />
<beans:property name="suffix" value=".html" />
</beans:bean>
My web.xml
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></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>
Controller method:
#RequestMapping(value = "/", method = RequestMethod.GET)
public String homePage(ModelMap model, HttpServletRequest servletRequest, HttpServletResponse response) {
String returnText = "static/html/index";
return returnText;
}
I have searched and implemented various ways. Its now working like a boss.
Below link helped me and stiched my time a lot. Also need to work various html files with this solution.
Spring MVC ViewResolver not mapping to HTML files
I have given my welcome file in web.xml
But when running the application, it is showing 404 error on http://172.16.2.16:8080/sampletest/
It is a spring application.
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>sampletest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- Spring MVC -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I am using eclipse luna, java 8, tomcat 8 and maven framework.
index.html file is directly under webapp folder and web.xml is under webapp/WEB-INF folder.
If I use index.jsp instead of index.html, it is working. Then welcome page will load using http://172.16.2.16:8080/sampletest/
The issue is only with welcome file. Otherwise spring configuration is working.
http://localhost:8080/sampletest/test/ will load the data from database.
Error log in console
......................
Jul 10, 2014 12:38:42 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4963 ms
Jul 10, 2014 12:38:42 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/sampletest/] in DispatcherServlet with name 'dispatcher'
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
Dispatcher
<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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<context:annotation-config />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<context:component-scan base-package="com.sample.test" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="packagesToScan">
<array>
<value>com.sample.test.domain</value>
</array>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.connection.characterEncoding">UTF-8</prop>
<prop key="hibernate.connection.useUnicode">true</prop>
<prop key="hibernate.connection.CharSet">UTF-8</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/sampletest?autoConnect=true" />
<property name="user" value="root" />
<property name="password" value="root" />
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- HibernateTransactionManager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
<property name="flushModeName">
<value>FLUSH_AUTO</value>
</property>
</bean>
</beans>
Controller
package com.sample.test.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.sample.test.dto.Response;
import com.sample.test.facade.AccelFlowFacade;
#Controller
public class SampleTestController {
#Autowired
#Qualifier("sampleTestFacade")
SampleTestFacade sampleTestFacade;
public SampleTestFacade getSampleTestFacade() {
return sampleTestFacade;
}
public void setSampleTestFacade(SampleTestFacade sampleTestFacade) {
this.sampleTestFacade= sampleTestFacade;
}
#RequestMapping(value = "/test", method = RequestMethod.GET)
public #ResponseBody Response display() throws Exception {
sampleTestFacade.disaply();
Response res = new Response();
return res;
}
}
Try adding <mvc:default-servlet-handler/> in your dispatcher-servlet.xml.
See here for details.
You have mapped all your incoming requests to the dispatcher here,
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
So all your URL requests for the application goes inside the dispatcher as '/' maps all incoming requests . check for the stacktraces in your application server log
update:
You get the below warning because there are no handler for the '/' pattern,
WARNING: No mapping found for HTTP request with URI [/AccelFlow/] in
DispatcherServlet with name 'dispatcher'
You can do either of below options ,
Map a url with '/' to the controller
Add a specific URL pattern to the spring dispatcher such as .htm or .do as you wish
Modify your web.xml,
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
And in your controller,
#RequestMapping(value = "/test.htm", method = RequestMethod.GET)
public #ResponseBody Response display() throws Exception {
accelFlowFacade.disaply();
Response res = new Response();
return res;
}
At the startup by default all incoming requests are mapping to '/' pattern as you write in the web.xml:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
update:
Try to map a Controller method for the default view:
#RequestMapping(value = "/", method = GET)
public String welcome() {
return "index";
}
Add viewresolver to dispather-servlet.xml:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/"
p:suffix=".jsp" />
Remove welcome file from the web.xml as automatically spring will search for index page by default:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Welcome file can be access using following changes.
change 1. add resource path in dispatcher as following :
<mvc:resources mapping="/" location="/index.html" />
change 2. add controller handler like following :
#Controller
public class RestController {
#RequestMapping(value = "/", method = RequestMethod.GET)
public String welcome() {
return "index.html";
}
}
changes 3: index.html file should be in WebContent folder in project.
Note : If you are not able to add mvc bean in dispatcher servlet file then add
xmlns:mvc="http://www.springframework.org/schema/mvc
in dispatcher servlet config file.
using <mvc:resources mapping="/" location="/index.html" /> is goods for static pages , however changing it to
#RequestMapping(value = "/", method = RequestMethod.GET)
public String welcome() {
return "index.html";
}
is not good design as all model in other controllers may point back to index page, instead use
<mvc:resources mapping="/" location="/redfresh.html" />
and make refresh page such
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="refresh" content="0;URL='/index'" />
</head>
<body>
</body>
</html>
and point in controller to index such:
#Controller
public class indexPageController {
#RequestMapping(value = "/index", method = RequestMethod.GET, produces = "text/html")
public String index() {
return "index";
}
}
Just add your index.html to webContent folder. Because welcome file is searched in that folder itself.
I am new to Spring social and trying to config spring social signin for linkedin.
My spring config file below,
<context:component-scan base-package="com.tc.web">
<context:include-filter type="regex"
expression="(service|controller|component)\..*" />
</context:component-scan>
<bean id="connectionFactoryLocator"
class="org.springframework.social.connect.support. ConnectionFactoryRegistry">
<property name="connectionFactories">
<list>
<bean
class="org.springframework.social.linkedin.connect .LinkedInConnectionFactory">
<constructor-arg value="key........" />
<constructor-arg value="secret .........." />
</bean>
</list>
</property>
</bean>
<bean id="textEncryptor" class="org.springframework.security.crypto.encrypt .Encryptors"
factory-method="noOpText" />
<bean id="usersConnectionRepository"
class="org.springframework.social.connect.jdbc.Jdb cUsersConnectionRepository">
<constructor-arg ref="dataSource" />
<constructor-arg ref="connectionFactoryLocator" />
<constructor-arg ref="textEncryptor" />
</bean>
<bean id="connectionRepository" factory-method="createConnectionRepository"
factory-bean="usersConnectionRepository" scope="request">
<constructor-arg value="#{request.userPrincipal.name}" />
<aop:scoped-proxy proxy-target-class="false" />
</bean>
<bean id="signInAdapter" class="com.tc.web.social.signin.SocialSignInAdapte r" />
<bean class="org.springframework.social.connect.web.Prov iderSignInController">
<!-- relies on by-type autowiring for the constructor-args -->
<constructor-arg ref="signInAdapter" />
<property name="applicationUrl" value="link" />
<property name="signUpUrl" value="link" />
<property name="signInUrl" value="link" />
</bean>
My SocialSignInAdapter.java is,
public class SocialSignInAdapter implements SignInAdapter{
#Override
public String signIn(String userId, Connection<?> connection, NativeWebRequest request) {
System.out.println("User Id is ===>>> "+userId);
System.out.println("Connection is ====>>> "+connection);
return null;
}
}
In Login.jsp,
<li class="linkedin"> </li>
When I click the above linkedin link, i get 404 error.
I guess my app is unable to find the ProviderSignInController for the request, ://dom:8080/myApp/signin/linkedin.
I suspect the below config in spring xml.
<context:component-scan base-package="com.tc.web">
<context:include-filter type="regex"
expression="(service|controller|component)\..*" />
</context:component-scan>
I have all my controller inside the package com.tc.web. But the ProviderSignInController is in Spring package and my app is unable to find it.
I tried the below as well.
<context:component-scan base-package="com.tc.web,org.springframework.social.con nect.web">
<context:include-filter type="regex"
expression="(service|controller|component)\..*" />
</context:component-scan>
I got ambigous mapping error for ProviderSignInController with the above config.
So, I removed the
<bean class="org.springframework.social.connect.web.Prov iderSignInController">
<!-- relies on by-type autowiring for the constructor-args -->
<constructor-arg ref="signInAdapter" />
<property name="applicationUrl" value="link" />
<property name="signUpUrl" value="link" />
<property name="signInUrl" value="link" />
</bean>
from my spring xml. But still I am getting the 404 error.
Could anyone help me on this please ..........
Thanks,
Baskar.S
The Controller that handles signin requests is org.springframework.social.connect.web.ProviderSignInController (present in spring-social-web-x.x.x.jar)
The Controller method is
#RequestMapping(value="/{providerId}", method=RequestMethod.POST)
public RedirectView signIn(#PathVariable String providerId, NativeWebRequest request)
So, as you can see, it only accepts POST requests. You will have to change the anchor link tag to a button that triggers a form submit.
e.g.
<form action="<c:url value="/signin/linkedin" />" method="POST" id="frmLiConnect"></form>
Secondly, in order for the Spring Controller, extend the ProviderSignInController with your own dummy Controller so that the Spring class is accessible.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.web.ProviderSignInController;
import org.springframework.social.connect.web.SignInAdapter;
import org.springframework.stereotype.Controller;
#Controller
public class SigninController extends ProviderSignInController {
#Autowired
public SigninController(ConnectionFactoryLocator connectionFactoryLocator,
UsersConnectionRepository usersConnectionRepository,
SignInAdapter signInAdapter) {
super(connectionFactoryLocator, usersConnectionRepository, signInAdapter);
// TODO Auto-generated constructor stub
}
}
For more details, you can also refer to the Spring Social Showcase examples at the below link.
https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase/src/main/java/org/springframework/social/showcase/signin
Hope this helps.
I would like to know which way of log exception in Spring.NET is prefered and why.
I found two common scenarios.
1.Use IThrowAdvice.
I created throws advice and in method AfterThrowing handle / log exception.
namespace Aspects
{
public class ExLogThrowsAdvice : IThrowsAdvice
{
private ILog _logger;
public ExLogThrowsAdvice()
{
_logger = LogManager.GetLogger("Error_file");
}
public void AfterThrowing(MethodInfo methodInfo,
Object []args, Object target, Exception exception)
{
_logger.Error(exception);
}
}
}
and use Common.Loggin API (Common Loggin API) for configuring for example Log4net for logging.
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<log4net>
<appender name="ErrorFileAppender"
type="log4net.Appender.FileAppender">
<file value="errors.txt"/>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date%newline%username%newline[%thread] %message %newline"/>
</layout>
</appender>
<root>
<level value="ERROR"/>
<appender-ref ref="ErrorFileAppender"/>
</root>
</log4net>
And last, create a proxy for the object in the businees layer.
<!--ex log advice-->
<object id="theExLogAdvice" type="Aspects.ExLogThrowsAdvice, ExceptionLogging"/>
<!--auto proxy creator-->
<object type="Spring.Aop.Framework.AutoProxy.TypeNameAutoProxyCreator, Spring.Aop">
<property name="TypeNames" value="Aspects*"/>
<property name="InterceptorNames">
<list>
<value>theExLogAdvice</value>
</list>
</property>
</object>
This is first concept. The second which I found is to use aspect fo exception handling from the Spring Aspect library.
2.Exception aspects from Spring.NET
I would like create a handler for log exception and this handler will use the Log4net logger.
Handler for exception:
<object id="exLogHandler"
type="Spring.Aspects.Exceptions.LogExceptionHandler, Spring.Aop">
<property name="LogName" value="???"/>
<property name="LogLevel" value="Error"/>
</object>
and then use this handler in exception handle advice:
<object id="exLogAspect"
type="Spring.Aspects.Exceptions.ExceptionHandlerAdvice, Spring.Aop">
<property name="ExceptionHandlerDictionary">
<dictionary>
<entry key="log" ref="exLogHandler"/>
</dictionary>
</property>
<property name="ExceptionHandlers">
<list>
<value>on exception name SomeException log 'Ex:' + #e</value>
</list>
</property>
I am not sure if second way is good. Maybe it is stupidity.
It is possible configure LogExceptionHandler to use the Log4net logger?
I'm not sure if it's the best, but a SimpleLoggingAdvice logs exceptions for you. Furthermore, you can configure a SimpleLoggingAdvice to log execution time, method arguments and return values. Configuration looks like this (from the docs):
<object name="loggingAdvice" type="Spring.Aspects.Logging.SimpleLoggingAdvice, Spring.Aop">
<property name="LogUniqueIdentifier" value="true"/>
<property name="LogExecutionTime" value="true"/>
<property name="LogMethodArguments" value="true"/>
<property name="LogReturnValue" value="true"/>
<property name="Separator" value=";"/>
<property name="LogLevel" value="Info"/>
<property name="HideProxyTypeNames" value="true"/>
<property name="UseDynamicLogger" value="true"/>
</object>
Of course, you still have to configure a proxy factory and logging, but you know how to do that already.
What I am aiming to do is to configure spring mvc 3 to not return “null” object in json response.
I've asked the question how to configure spring mvc 3 to not return "null" object in json response? . And the suggestion I got is to configure the ObjectMapper, setting the serialization inclusion to JsonSerialize.Inclusion.NON_NULL. So Based on Spring configure #ResponseBody JSON format, I did the following changes in spring config file. But I got the error "Rejected bean name 'jacksonObjectMapper': no URL paths identified org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping:86-AbstractDetectingUrlHandlerMapping.java" during app startup.
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- Configures the #Controller programming model -->
<mvc:annotation-driven />
<!-- Forwards requests to the "/" resource to the "welcome" view -->
<!--<mvc:view-controller path="/" view-name="welcome"/>-->
<!-- Configures Handler Interceptors -->
<mvc:interceptors>
<!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>
<!-- Saves a locale change using a cookie -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="jacksonObjectMapper" />
</bean>
</list>
</property>
</bean>
<bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" />
<bean id="jacksonSerializationConfig" class="org.codehaus.jackson.map.SerializationConfig"
factory-bean="jacksonObjectMapper" factory-method="getSerializationConfig" />
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="jacksonSerializationConfig" />
<property name="targetMethod" value="setSerializationInclusion" />
<property name="arguments">
<list>
<value type="org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion">NON_DEFAULT</value>
</list>
</property>
</bean>
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
I have no idea why it's been rejected. Any suggestion is greatly appreciated!
<mvc:annotation-driven /> and AnnotationMethodHandlerAdapter cannot be used together. (ref: spring forum thread). Possible solution
do not use <mvc:annotation-driven/>. Declaring bean: DefaultAnnotationHandlerMapping
and AnnotationMethodHandlerAdapter and other settings like validation, formatting.
use spring 3.1, which has <mvc:message-converters> (ref: Spring jira)