Help with Spring 3.2.1.RELEASE - Controller not launching
Hi everybody,
I'm posting here because I'm trying to create some spring web app, but I fail to launch a controller... Maybe I miss something.
Here are my config files, so you can have a look. I really don't understand what's wrong, as it should work ...
First the controller itself:
Code:
package be.rvk.iwc.web.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* @author Romain Van der Keilen
*/
@Controller
public class FrontController {
public static final Logger logger = LoggerFactory.getLogger(FrontController.class);
@RequestMapping("/index")
public ModelAndView getMainIndexPage() {
logger.debug("Serving homepage");
return new ModelAndView("home");
}
}
Then, the web.xml:
Code:
<?xml version = '1.0' encoding = 'UTF-8'?>
<web-app [...] >
<display-name>IWC</display-name>
<!-- Log4J Initialization Config -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1000</param-value>
</context-param>
<!-- Log4J Initialization -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<filter>
<filter-name>encoding-filter</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>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
- Location of the XML file that defines the root application context
- Applied by ContextLoaderListener.
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext.xml
classpath:/repositoriesApplicationContext.xml
classpath:/servicesApplicationContext.xml
</param-value>
</context-param>
<filter>
<!-- The name of the filter must the same than the FilterChainProxy bean -->
<filter-name>filterChainProxy</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>filterChainProxy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--
- Loads the root application context of this web app at startup.
- The application context is then available via
- WebApplicationContextUtils.getWebApplicationContext(servletContext).
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring Initialization -->
<servlet>
<servlet-name>springWeb</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/springWeb-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springWeb</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<error-page>
<error-code>500</error-code>
<location>/error/error500.htm</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error/error404.htm</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/error/error403.htm</location>
</error-page>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
then, the applicationContext.xml (repository works fine, and service is still empty)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans [...]>
<context:property-placeholder location="classpath:application.properties" />
</beans>
Finally, the springWeb-servlet.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans [...]>
<context:component-scan base-package="be.rvk.iwc" />
<mvc:annotation-driven />
<!-- Spring MVC Controller -->
<bean id="myController" class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="defaultHandler">
<bean class="be.rvk.iwc.web.controller.FrontController" ></bean>
</property>
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
<!-- Enables plain Controllers -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<!-- Enables annotated POJO @Controllers -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<!-- Enable the locale System -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>/WEB-INF/i18n/messages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
<property name="cacheSeconds" value="1" />
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="fr" />
</bean>
<!-- Resolves logical view names returned by Controllers to Tiles; a view name to resolve is treated as the name of a tiles definition -->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
<!-- Configures the Tiles layout system -->
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/templates/templates.xml</value>
<value>/WEB-INF/pages/pages.xml</value>
</list>
</property>
</bean>
<!-- TODO values must be tiles view names -->
<!-- bean id="handlerExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<util:map>
<entry key="org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException" value="error404" />
</util:map>
</property>
<property name="defaultErrorView" value="error500" />
<property name="warnLogCategory" value="consoleAppender" />
</bean -->
</beans>
I really have no more idea ....
Thanks for your time!
Romain.