2012-11-20 44 views
1

我在grails中成功創建了cxf wsdl web-services。現在我想配置cxf簡單的前端端點。在resources.groovy中使用DSL代替resource.xml配置CXF服務

我在grails項目的resource.xml文件中成功配置了cxf endpoint。

如..

<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文件,而不是創造新的resource.xml相同CXF端點配置。

有人有想法嗎?

回答

1

可以代替<import>元素

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

,爲<simple:server>您可以直接在DSL複製此的使用importBeans(見「使用Spring命名空間」在this section of the user guide末)

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") 

(NB如果FaxSignupServicegrails-app/services那麼它已註冊爲默認和額外的bean定義一個bean下一個真正的Grails的服務是不需要的,只需添加serviceBean:'#faxSignupService'simple.server就夠了。)

+0

非常感謝伊恩,工作正常。感謝您在短時間內給予回覆。 –

+0

你好伊恩,它工作正常。但是我得到了com.j2.signup.FaxSignupService中** def dataSource **的空值。我想使用grails dataSource服務從數據庫中獲取數據。你對此有任何想法? –

+0

@ChiragDasani我已經添加了一些關於這種情況的更多細節。 –