使用xml时使用以下配置使报文没有加上命名空间时也能正常访问接口。bean定义的前后顺序不影响程序正常注册对象。
<!-- 通过Spring创建数据绑定的类 --> <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding" />
<bean id="jaxWsServiceFactoryBean" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" scope="prototype"> <property name="wrapped" value="true" /> <property name="dataBinding" ref="aegisBean" /> </bean>
<jaxws:endpoint id="imSendWXModelMessageServicews" implementor="#imSendWXModelMessageService" address="/imSendWXModelMessageService.ws"> <jaxws:serviceFactory> <ref bean="jaxWsServiceFactoryBean" /> </jaxws:serviceFactory> </jaxws:endpoint>
但是如果使用springboot的话,使用注解方式配置,需要注意的是,需要使用到的类一定要放在前面先初始化。不然会没有效果。
例如下面代码红色部分。如果放在endpoint.publish()后面则不会生效。
@Bean public AegisDatabinding aegisDatabinding() { return new AegisDatabinding(); } @Bean @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public JaxWsServiceFactoryBean jaxWsServiceFactoryBean() { org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean sf = new JaxWsServiceFactoryBean(); sf.setWrapped(true); sf.setDataBinding(aegisDatabinding()); return sf; } @Bean public Endpoint sendMessageEndpoint(SendMessageService sendMessageService) { EndpointImpl endpoint = new EndpointImpl(sendMessageService); endpoint.setServiceFactory(jaxWsServiceFactoryBean()); endpoint.publish("/imSendWXModelMessageService.ws"); return endpoint; }