使用DSL而不是resource.xml在resources.groovy中配置CXF服务

时间:2012-11-20 09:02:49

标签: grails cxf

我在grails中成功创建了cxf wsdl web-services。现在我想配置cxf简单的前端端点。

我在grails项目的resource.xml文件中成功配置了cxf端点。

像..

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:simple="http://cxf.apache.org/simple"
    xmlns:lang="http://www.springframework.org/schema/lang"
    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://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.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" />

    <!--create CXF service-->
<simple:server serviceClass="com.j2.signup.FaxSignupService" address="/FaxSignupService">

</simple:server>
</beans>

但我想在resource.groovy DSL文件中使用相同的cxf端点配置,而不是创建新的resource.xml。

有人对此有所了解吗?

1 个答案:

答案 0 :(得分:1)

您可以使用importBeans代替<import>元素

importBeans('classpath:META-INF/cxf/cxf.xml')

对于<simple:server>,你可以直接在DSL中复制它(参见this section of the user guide末尾的“使用Spring命名空间”)

xmlns simple:'http://cxf.apache.org/simple'
simple.server(serviceClass:"com.j2.signup.FaxSignupService",
              address:"/FaxSignupService")

如果你的FaxSignupService类本身需要Spring注入的依赖项,那么你需要将它声明为顶级bean

faxSignupService(com.j2.signup.FaxSignupService) { bean ->
  bean.autowire = "byName"
}
xmlns simple:'http://cxf.apache.org/simple'
simple.server(serviceClass:"com.j2.signup.FaxSignupService",
              serviceBean:"#faxSignupService",
              address:"/FaxSignupService")

(如果FaxSignupServicegrails-app/services下的正版Grails服务,那么它默认已经注册为bean,并且不需要额外的bean定义,只需添加serviceBean:'#faxSignupService'即可simple.server就够了。)