android - No suitable HttpMessageConverter for Respose -
i beginner in android.i need call spring web service in android project returns class object response.below code used call web service.
int nid=4; resttemplate resttemplate=new resttemplate(); coaaccountlist acclist=resttemplate.getforobject("http://localhost:8080/springproject/getcoalist/{parentid}", coaaccountlist.class, nid);
below controller code web-service comes hit.
@requestmapping(value = "/getcoalist/{parentid}",method = requestmethod.get) public @responsebody coaaccountlist getcoalist(@pathvariable(value ="parentid") integer parentid) { try{ system.out.println("coaacclist "); coaaccountlist coaacclist=new coaaccountlist(); list<coaaccount> accountlist= saveitdao.getaccounts(parentid); coaacclist.setcoalist(accountlist); return coaacclist; }catch(exception e){ system.out.println("exc on list "+e); return null; } }
im getting :-
org.springframework.web.client.resourceaccessexception: not extract response: no suitable httpmessageconverter found response type[com.example.myandroidproject.coaaccountlist] , content type [application/json].
i don't know how convert response coaaccountlist object in android.how that? please me.i have web-service returns jsonstring, working perfectly.
string acclist=resttemplate.getforobject("http://localhost:8080/springproject/getallaccounts/{parentid}", string.class, nid);
below spring configuration file.
servlet-context.xml:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:annotation-config /> <mvc:annotation-driven /> <context:component-scan base-package="com.example.save" /> <!-- <bean id="jspviewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/view/" /> <property name="suffix" value=".jsp" /> <property name="order" value="1" /> </bean> --> <bean id="viewresolver" class="org.springframework.web.servlet.view.tiles3.tilesviewresolver"/> <bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles3.tilesconfigurer"> <property name="definitions"> <list> <value>/web-inf/layouts/layouts.xml</value> <value>/web-inf/layouts/views.xml</value> </list> </property> </bean> <bean id="mydatasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close"> <property name="driverclassname" value="com.mysql.jdbc.driver"/> <property name="url" value="jdbc:mysql://localhost:3306/springproject"/> <property name="username" value="root"/> <property name="password" value="password"/> <property name="validationquery" value="select 1"/> </bean> <!-- hibernate session factory --> <bean id="mysessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="mydatasource"/> <property name="packagestoscan"> <array> <value>com.example.save</value> </array> </property> <property name="hibernateproperties"> <value> hibernate.dialect=org.hibernate.dialect.mysqldialect </value> </property> </bean> <!-- hibernate transaction manager --> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="mysessionfactory"/> </bean> <mvc:resources mapping="/resources/**" location="/web-inf/resources/" /> <!-- activates annotation based transaction management --> <tx:annotation-driven transaction-manager="transactionmanager"/> </beans>
as cans ee using tilesviewresolver; viewresolver tries respond in html; suggest use org.springframework.web.servlet.view.contentnegotiatingviewresolver (an article available here spring contentnegotingviewresolver
basically point spring tries respond in html since using tilesviewresolver; need, instead, json response in "mix" kind of response, contentnegotiatingviewresolver can you
Comments
Post a Comment