不罗嗦,直接问题描述:我在使用java优先的方式写CXF服务时,因为用到了Map类型,所以想到使用CXF框架非默认的Aegis数据绑定方式。但是按照我自以为的方式配置的bean文件,在发布时遇到了异常:
异常摘要
nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'dataBinding' of bean class [org.apache.cxf.jaxws.spring.EndpointDefinitionParser$SpringEndpointImpl]: Bean property 'dataBinding' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Invalid property 'dataBinding' of bean class [org.apache.cxf.jaxws.spring.EndpointDefinitionParser$SpringEndpointImpl]: Bean property 'dataBinding' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
我原来的配置文件为:
<?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:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="LabsQuerying" implementor="rc.yuzone.services.LabsQueryImpl" address="/LabsQueryingService"> <jaxws:dataBinding> <bean class="org.apache.cxf.aegis.databinding.AegisDatabinding" /> </jaxws:dataBinding> </jaxws:endpoint> </beans>
后来谷歌了好久,终于在一张已经被删了的网页中(还好有快照功能)找到了灵感,我修改了配置文件,用了另一种绑定方式:
<?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:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="LabsQuerying" implementor="rc.yuzone.services.LabsQueryImpl" address="/LabsQueryingService"> <jaxws:serviceFactory> <bean class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"> <property name="dataBinding" ref="aegisBean" /> <property name="serviceConfigurations"> <list> <bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration" /> <bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration" /> <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration" /> </list> </property> </bean> </jaxws:serviceFactory> </jaxws:endpoint> <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding"/> </beans>
如此修改以后再部署,Spring就不报错了,至少可以部署成功了。至于是否影响后续的开发,还有待时间检验;至于为什么,再研究吧。