Detecting Mobile Device in Spring -


i'm having spring boot application. trying figure out type of device request has been instantiated.

i have added spring mobile device jar in pom.xml

pom.xml :

<dependency>     <groupid>org.springframework.mobile</groupid>     <artifactid>spring-mobile-device</artifactid> </dependency> 

controllerconfig:

@configuration public class controllerconfig  extends webmvcconfigureradapter {  @bean public devicehandlermethodargumentresolver devicehandlermethodargumentresolver() {     return new devicehandlermethodargumentresolver(); }  @override public void addargumentresolvers(list<handlermethodargumentresolver> argumentresolvers) {      argumentresolvers.add(new servletwebargumentresolveradapter(              new devicewebargumentresolver()));          argumentresolvers              .add(new sitepreferencehandlermethodargumentresolver()); } } 

i have controller class uses device request parameter.

controller.java :

  @requestmapping(value = "/device",method=requestmethod.get)   @responsestatus(httpstatus.ok)   public responseentity<byte[]> getdeviceinfo(device device){     if (device != null && device.isnormal()) {             system.out.println("*******normal******");         }else if(device != null && (device.ismobile() || device.istablet())){             system.out.println("*******mobile******");         }   } 

when run code, following error:

org.springframework.web.util.nestedservletexception: request processing failed; nested exception org.springframework.beans.beaninstantiationexception: failed instantiate [org.springframework.mobile.device.device]: specified class interface @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:978) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:857) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ javax.servlet.http.httpservlet.service(httpservlet.java:687) ~[javax.servlet-api-3.1.0.jar:3.1.0] @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ javax.servlet.http.httpservlet.service(httpservlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0] @ io.undertow.servlet.handlers.servlethandler.handlerequest(servlethandler.java:85) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.filterhandler$filterchainimpl.dofilter(filterhandler.java:130) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) ~[spring-web-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) ~[spring-web-4.1.4.release.jar:4.1.4.release] @ io.undertow.servlet.core.managedfilter.dofilter(managedfilter.java:60) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.filterhandler$filterchainimpl.dofilter(filterhandler.java:132) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.filterhandler.handlerequest(filterhandler.java:85) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.security.servletsecurityrolehandler.handlerequest(servletsecurityrolehandler.java:61) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.servletdispatchinghandler.handlerequest(servletdispatchinghandler.java:36) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.security.sslinformationassociationhandler.handlerequest(sslinformationassociationhandler.java:131) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.security.servletauthenticationcallhandler.handlerequest(servletauthenticationcallhandler.java:56) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) ~[undertow-core-1.1.1.final.jar:1.1.1.final] @ io.undertow.security.handlers.abstractconfidentialityhandler.handlerequest(abstractconfidentialityhandler.java:45) ~[undertow-core-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.security.servletconfidentialityconstrainthandler.handlerequest(servletconfidentialityconstrainthandler.java:63) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.security.handlers.authenticationmechanismshandler.handlerequest(authenticationmechanismshandler.java:58) ~[undertow-core-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.security.cachedauthenticatedsessionhandler.handlerequest(cachedauthenticatedsessionhandler.java:70) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.security.handlers.securityinitialhandler.handlerequest(securityinitialhandler.java:76) ~[undertow-core-1.1.1.final.jar:1.1.1.final] @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) ~[undertow-core-1.1.1.final.jar:1.1.1.final] @ io.undertow.server.handlers.predicatehandler.handlerequest(predicatehandler.java:43) ~[undertow-core-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.servletinitialhandler.handlefirstrequest(servletinitialhandler.java:261) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.servletinitialhandler.dispatchrequest(servletinitialhandler.java:247) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.servletinitialhandler.access$000(servletinitialhandler.java:76) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.servlet.handlers.servletinitialhandler$1.handlerequest(servletinitialhandler.java:166) ~[undertow-servlet-1.1.1.final.jar:1.1.1.final] @ io.undertow.server.connectors.executeroothandler(connectors.java:197) ~[undertow-core-1.1.1.final.jar:1.1.1.final] @ io.undertow.server.httpserverexchange$1.run(httpserverexchange.java:759) [undertow-core-1.1.1.final.jar:1.1.1.final] @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) [na:1.8.0_40] @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) [na:1.8.0_40] @ java.lang.thread.run(thread.java:745) [na:1.8.0_40]  caused by: org.springframework.beans.beaninstantiationexception: failed instantiate [org.springframework.mobile.device.device]: specified class interface @ org.springframework.beans.beanutils.instantiateclass(beanutils.java:101) ~[spring-beans-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.method.annotation.modelattributemethodprocessor.createattribute(modelattributemethodprocessor.java:140) ~[spring-web-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.mvc.method.annotation.servletmodelattributemethodprocessor.createattribute(servletmodelattributemethodprocessor.java:79) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.method.annotation.modelattributemethodprocessor.resolveargument(modelattributemethodprocessor.java:106) ~[spring-web-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.method.support.handlermethodargumentresolvercomposite.resolveargument(handlermethodargumentresolvercomposite.java:77) ~[spring-web-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.method.support.invocablehandlermethod.getmethodargumentvalues(invocablehandlermethod.java:162) ~[spring-web-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:129) ~[spring-web-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:777) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:706) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:943) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:877) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966) ~[spring-webmvc-4.1.4.release.jar:4.1.4.release] ... 32 common frames omitted 

is there way resolve error.?

although have declared devicehandlermethodargumentresolver bean, have not added required resolver in addargumentresolvers. code should be:

@override public void addargumentresolvers(list<handlermethodargumentresolver> argumentresolvers) {   argumentresolvers.add(devicehandlermethodargumentresolver());    argumentresolvers.add(new servletwebargumentresolveradapter(new devicewebargumentresolver()));    argumentresolvers.add(new sitepreferencehandlermethodargumentresolver()); } 

you should consider declaring sitepreferencehandlermethodargumentresolver , servletwebargumentresolveradapter beans.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -