Spring Mobileを試していますが、基本的な例が機能していないようです。ばかげてシンプルなものが欠けているような気がしますが、それが何なのかわかりません。これが私が用意しているものです...
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
デバイスが設定されず、結果がnullになるのはなぜですか?
編集:ログファイルはインターセプターの設定に問題があることを示しているようですが、どこが間違っているのかまだわかりません。
タイプ'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]に変換できません:一致するエディターまたは変換戦略が見つかりません