Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:03:40+00:00 2026-06-05T15:03:40+00:00

I’m experimenting with Spring Mobile but I can’t seem to get the basic example

  • 0

I’m experimenting with Spring Mobile but I can’t seem to get the basic example working. I have a feeling I’m missing something stupidly simple but I can’t figure out what it is. Here is what I have in place…

In 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>

In 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>

In my Java class:

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

Why is the device not set and resulting as null?

EDIT:
Log files seem to indicate a problem with setting the interceptor but I’m still not sure where I went wrong.

2012-05-29 09:36:36,696 DEBUG [ConstructorResolver.java:201] :
Ignoring constructor [public
org.springframework.web.servlet.handler.MappedInterceptor(java.lang.String[],org.springframework.web.context.request.WebRequestInterceptor)]
of bean ‘org.springframework.web.servlet.handler.MappedInterceptor#0’:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name
‘org.springframework.web.servlet.handler.MappedInterceptor#0’:
Unsatisfied dependency expressed through constructor argument with
index 1 of type
[org.springframework.web.context.request.WebRequestInterceptor]: Could
not convert constructor argument value of type
[org.springframework.mobile.device.DeviceResolverHandlerInterceptor]
to required type
[org.springframework.web.context.request.WebRequestInterceptor]:
Failed to convert value of type
‘org.springframework.mobile.device.DeviceResolverHandlerInterceptor’
to required type
‘org.springframework.web.context.request.WebRequestInterceptor’;
nested exception is java.lang.IllegalStateException: Cannot convert
value of type
[org.springframework.mobile.device.DeviceResolverHandlerInterceptor]
to required type
[org.springframework.web.context.request.WebRequestInterceptor]: no
matching editors or conversion strategy found

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:03:44+00:00Added an answer on June 5, 2026 at 3:03 pm

    I’ve had a look at this and managed to get it to work myself. So I have a few comments.

    1a) I don’t think both the Filter and the Interceptor are required. I’ve just used the Filter and that was enough.

    1b) The Interceptor (if used) should be configured in a DispatcherServlet xml config file. You look like you are using Struts from the use of ActionSupport, is this correct? If so, you (probably) won’t have a DispatcherServlet and therefore I don’t think this config will work as expected. I think that’s why you’re getting the stack trace.

    2) I would add a breakpoint to org.springframework.mobile.device.DeviceResolverRequestFilter.doFilterInternal to make sure it’s being executed.

    3) I would check that Struts isn’t doing something ‘funny’ with the ServletRequest, and hiding the “currentDevice” request attribute from you somehow. In fact, I would port your code to vanilla Spring if possible.

    4) Maybe you could use ServletActionContext.getRequest in your execute method and see if that works, and/or compare the returned request to that set in setServletRequest.


    Using Spring MVC, this is what works for me. My project is called spring-mobile-test, and “spring-mobile-test” is its context root:

    web.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <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" version="2.5">
        <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>
        <servlet>
            <servlet-name>mvc</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>mvc</servlet-name>
            <url-pattern>/mvc/*</url-pattern>
        </servlet-mapping>
    </web-app>
    

    applicationContext.xml is empty.

    mvc-servlet.xml:

    <beans xmlns="http://www.springframework.org/schema/beans" 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/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">
    
        <context:component-scan base-package="temp" />
    
    </beans>
    

    temp.TestController:

    package temp;
    
    import javax.servlet.http.HttpServletRequest;
    
    import org.apache.log4j.Logger;
    import org.springframework.mobile.device.Device;
    import org.springframework.mobile.device.DeviceUtils;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    public class TestController {
        private static final Logger logger = Logger.getLogger(TestController.class);
    
        @RequestMapping("/")
        public @ResponseBody
        String home(HttpServletRequest req) {
            Device device = DeviceUtils.getCurrentDevice(req);
            String msg = "";
            if (device.isMobile()) {
                msg = "Hello mobile user!";
            } else {
                msg = "Hello desktop user!";
            }
            logger.info(msg);
            return msg;
        }
    }
    

    The browser shows the following text when I browse to the URL http://localhost/spring-mobile-test/mvc/:

    Hello desktop user!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.