Could not find MessageBodyWriter for response object of type: java.util.ArrayList
解决办法:war包要包含提供rest服务的ejb LOCAL接口类
我的打包参考:
1、build.ejblocal.xml片段
<target name="ejb-local.jar"> <jar jarfile="${temp.dir}/ejb-local.jar"> <fileset dir="./${classes.dir}"> <include name="**/IHelloWorldLocal.class" /> <include name="**/Book.class" /> <!--include name="**/jboss-deployment-structure.xml" /--> </fileset> </jar> </target>说明:IHelloWorldLocal是ejb LOCAL接口,包含rest声明,类中有一个方法,返回值为List<Book>;Book是vo类。打包生成ejb-local.jar
2、build.ejbimpl.xml片段
<target name="ejb-impl.jar"> <jar jarfile="${temp.dir}/ejb-impl.jar"> <fileset dir="./${classes.dir}"> <include name="**/HelloWorldBean.class" /> <include name="**/jboss-deployment-structure.xml" /> </fileset> </jar> </target>说明:HelloWorldBean是IHelloWorldLocal的实现类。打包生成ejb-impl.jar。
jboss-deployment-structure.xml如下,声明了对ejb-local.jar的依赖
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1"> <deployment> <dependencies> <module name="deployment.ejb-local.jar" /> </dependencies> </deployment> </jboss-deployment-structure>
<target name="deploy-war"> <jar jarfile="${temp.dir}/rest.war"> <fileset dir="./web/"> <include name="**/IHelloWorldLocal.class" /> <include name="**/web.xml" /> <include name="WEB-INF/jboss-deployment-structure.xml" /> </fileset> </jar> </target>说明:如果不包含<include name="**/IHelloWorldLocal.class" />,调用rest服务就会报上面的错误
<context-param> <param-name>resteasy.jndi.resources</param-name> <param-value> java:global/ejb-impl/HelloWorldBean!com.ejb.hello.IHelloWorldLocal </param-value> </context-param> <context-param> <param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/rest</param-value> </context-param> <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> <listener> <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> </listener> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping>WEB-INF/jboss-deployment-structure.xml的配置:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1"> <deployment> <dependencies> <module name="deployment.ejb-local.jar" /> <!-- <module name="org.jboss.resteasy.resteasy-jettison-provider"/> <module name="org.jboss.resteasy.resteasy-jackson-provider"/> --> <module name="org.jboss.resteasy.resteasy-jaxrs" /> <module name="org.jboss.resteasy.resteasy-jaxb-provider" /> </dependencies> </deployment> </jboss-deployment-structure>