我和春天实验移动,但我似乎无法获得基本的例子工作。我有一种感觉,我想的东西太简单,但我无法弄清楚它是什么。以下是我在的地方...Spring Mobile - Interceptor不适用?设备是空
在web.xml中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>deviceResolverRequestFilter</filter-name>
<filter-class>org.springframework.mobile.device.DeviceResolverRequestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>deviceResolverRequestFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在applicationContext.xml中
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:device="http://www.springframework.org/schema/mobile/device"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mobile/device
http://www.springframework.org/schema/mobile/device/spring-mobile-device-1.0.xsd">
<!-- Interceptors that execute common control logic across multiple requests -->
<interceptors>
<!-- Detects the client's Device -->
<beans:bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
</interceptors>
</beans:beans>
在我的Java类:
public class TestAction extends ActionSupport implements ServletRequestAware {
// So that we can lookup the current Device
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
@Override
public String execute() {
Device currentDevice = DeviceUtils.getCurrentDevice(request);
if (currentDevice.isMobile()) // <-- fails here with NPE
为什么该设备未设置并导致为空?
编辑: 日志文件似乎表明与设置拦截器有问题,但我仍然不知道我哪里错了。
2012-05-29 09:36:36696 DEBUG [ConstructorResolver.java:201]: 忽略构造[公共 org.springframework.web.servlet.handler.MappedInterceptor(java.lang.String中[] ,org.springframework.web.context.request.WebRequestInterceptor)] bean'org.springframework.web.servlet.handler.MappedInterceptor#0': org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为bean的错误 “org.springframework.web.servlet.handler.MappedInterceptor#0”: 不合格依赖通过构造器参数表示与类型的 索引[org.springframework.web.context.request.WebRequestInterceptor]:可能不 [org.springframework.mobile.device.DeviceResolverHandlerInterceptor] 类型的构造器参数值转换为所需的类型 [org.springframework.web.context。 request.WebRequestInterceptor]: 未能转换类型 'org.springframework.mobile.device.DeviceResolverHandlerInterceptor' 所需类型 'org.springframework.web.context.request.WebRequestInterceptor' 的值; 嵌套异常是java.lang.IllegalStateException:不能 [org.springframework.mobile.device.DeviceResolverHandlerInterceptor] 类型的 值转换为所需的类型 [org.springframework.web.context.request.WebRequestInterceptor]:无 匹配编辑或转换策略找到
正如我以为......这是一个非常愚蠢的错误,没有人能够在这里确定,因为我没有发布整个'web.xml'内容。我有我的过滤器设置倒退!你的建议#2帮助我在正确的地方设置断点来实现我的错误。我相信我需要过滤器和拦截器才能让我的应用程序工作......至少在我的情况下。 – nmc