2012-05-02 77 views
1

我試圖使用Grails和Apache CXF創建Web服務,自然使用CXF-Grails插件。我創建了一個名爲測試服務無法使用Grails和CXF插件創建Web服務bean

package testcxf 

class TestService { 

    static expose = ['cxf'] 

    String echoString(String str) { 
     return str 
    } 

    String reverseString(String str) { 
     return str.reverse() 
    } 
} 

一個簡單的服務這個服務的工作原理完全如預期測試客戶端成功地稱爲回聲和反向的方法。接下來,我創建了一個叫做人

package testcxf 

class Person { 

    String name 
    String city 
    int age 

    static constraints = { 
    } 
} 

一個簡單的域類,並且使用一些基本的功能修改了服務與結構域相互作用。

package testcxf 

class TestService { 

    static expose = ['cxf'] 

    String echoString(String str) { 
     return str 
    } 

    String reverseString(String str) { 
     return str.reverse() 
    } 

    void addPerson(Person person) { 
     person.save() 
    } 

    Person getPerson(String name) { 
     return Person.findByName(name) 
    } 

    List<Person> getAllPeople() { 
     return Person.findAll() 
    } 
} 

這就是當它全部崩潰。當調用grails run-app時,我收到以下異常。該應用程序確實完成了啓動,但生成的wsdl不完整,缺少複雜類型Person的所有定義。

| Error 2012-05-01 20:51:03,504 [pool-7-thread-1] ERROR [localhost].[/TestCxf] - StandardWrapper.Throwable 
Message: Error creating bean with name 'testServiceBean': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.apache.cxf.endpoint.Server org.apache.cxf.frontend.ServerFactoryBean.create()] threw exception; nested exception is org.apache.cxf.service.factory.ServiceConstructionException 
    Line | Method 
->> 578 | createApplicationContext in grails.spring.BeanBuilder 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|  57 | loadAdditionalConfig  in org.grails.cxf.GrailsCXFServlet 
|  40 | init . . . . . . . . . . in  '' 
| 334 | innerRun     in java.util.concurrent.FutureTask$Sync 
| 166 | run . . . . . . . . . . in java.util.concurrent.FutureTask 
| 1110 | runWorker    in java.util.concurrent.ThreadPoolExecutor 
| 603 | run . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run      in java.lang.Thread 

Caused by BeanDefinitionStoreException: Factory method [public org.apache.cxf.endpoint.Server org.apache.cxf.frontend.ServerFactoryBean.create()] threw exception; nested exception is org.apache.cxf.service.factory.ServiceConstructionException 
->> 578 | createApplicationContext in grails.spring.BeanBuilder 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|  57 | loadAdditionalConfig  in org.grails.cxf.GrailsCXFServlet 
|  40 | init . . . . . . . . . . in  '' 
| 334 | innerRun     in java.util.concurrent.FutureTask$Sync 
| 166 | run . . . . . . . . . . in java.util.concurrent.FutureTask 
| 1110 | runWorker    in java.util.concurrent.ThreadPoolExecutor 
| 603 | run . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run      in java.lang.Thread 

Caused by ServiceConstructionException: null 
->> 341 | initialize    in org.apache.cxf.jaxb.JAXBDataBinding 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|  86 | initializeDataBindings in org.apache.cxf.service.factory.AbstractServiceFactoryBean 
| 442 | buildServiceFromClass . in org.apache.cxf.service.factory.ReflectionServiceFactoryBean 
| 505 | initializeServiceModel in  '' 
| 242 | create . . . . . . . . . in  '' 
| 101 | createEndpoint   in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory 
| 148 | create . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean 
| 578 | createApplicationContext in grails.spring.BeanBuilder 
|  57 | loadAdditionalConfig . . in org.grails.cxf.GrailsCXFServlet 
|  40 | init      in  '' 
| 334 | innerRun . . . . . . . . in java.util.concurrent.FutureTask$Sync 
| 166 | run      in java.util.concurrent.FutureTask 
| 1110 | runWorker . . . . . . . in java.util.concurrent.ThreadPoolExecutor 
| 603 | run      in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . . . . . . . . in java.lang.Thread 

Caused by IllegalAnnotationsException: 5 counts of IllegalAnnotationExceptions 
->> 102 | check     in com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 472 | getTypeInfoSet   in com.sun.xml.bind.v2.runtime.JAXBContextImpl 
| 302 | <init> . . . . . . . . . in  '' 
| 1140 | build     in com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder 
| 154 | createContext . . . . . in com.sun.xml.bind.v2.ContextFactory 
| 121 | createContext   in  '' 
| 248 | newInstance . . . . . . in javax.xml.bind.ContextFinder 
| 235 | newInstance    in  '' 
| 432 | find . . . . . . . . . . in  '' 
| 637 | newInstance    in javax.xml.bind.JAXBContext 
| 564 | createContext . . . . . in org.apache.cxf.jaxb.JAXBDataBinding 
| 504 | createJAXBContextAndSchemas in  '' 
| 324 | initialize . . . . . . . in  '' 
|  86 | initializeDataBindings in org.apache.cxf.service.factory.AbstractServiceFactoryBean 
| 442 | buildServiceFromClass . in org.apache.cxf.service.factory.ReflectionServiceFactoryBean 
| 505 | initializeServiceModel in  '' 
| 242 | create . . . . . . . . . in  '' 
| 101 | createEndpoint   in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory 
| 148 | create . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean 
| 578 | createApplicationContext in grails.spring.BeanBuilder 
|  57 | loadAdditionalConfig . . in org.grails.cxf.GrailsCXFServlet 
|  40 | init      in  '' 
| 334 | innerRun . . . . . . . . in java.util.concurrent.FutureTask$Sync 
| 166 | run      in java.util.concurrent.FutureTask 
| 1110 | runWorker . . . . . . . in java.util.concurrent.ThreadPoolExecutor 
| 603 | run      in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . . . . . . . . in java.lang.Thread 
| Error 2012-05-01 20:51:03,570 [pool-7-thread-1] ERROR [localhost].[/TestCxf] - Servlet /TestCxf threw load() exception 
Message: 5 counts of IllegalAnnotationExceptions 
    Line | Method 
->> 102 | check      in com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 472 | getTypeInfoSet    in com.sun.xml.bind.v2.runtime.JAXBContextImpl 
| 302 | <init> . . . . . . . . . . in  '' 
| 1140 | build      in com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder 
| 154 | createContext . . . . . . . in com.sun.xml.bind.v2.ContextFactory 
| 121 | createContext    in  '' 
| 248 | newInstance . . . . . . . . in javax.xml.bind.ContextFinder 
| 235 | newInstance     in  '' 
| 432 | find . . . . . . . . . . . in  '' 
| 637 | newInstance     in javax.xml.bind.JAXBContext 
| 564 | createContext . . . . . . . in org.apache.cxf.jaxb.JAXBDataBinding 
| 504 | createJAXBContextAndSchemas in  '' 
| 324 | initialize . . . . . . . . in  '' 
|  86 | initializeDataBindings  in org.apache.cxf.service.factory.AbstractServiceFactoryBean 
| 442 | buildServiceFromClass . . . in org.apache.cxf.service.factory.ReflectionServiceFactoryBean 
| 505 | initializeServiceModel  in  '' 
| 242 | create . . . . . . . . . . in  '' 
| 101 | createEndpoint    in org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory 
| 148 | create . . . . . . . . . . in org.apache.cxf.frontend.ServerFactoryBean 
| 578 | createApplicationContext in grails.spring.BeanBuilder 
|  57 | loadAdditionalConfig . . . in org.grails.cxf.GrailsCXFServlet 
|  40 | init      in  '' 
| 334 | innerRun . . . . . . . . . in java.util.concurrent.FutureTask$Sync 
| 166 | run       in java.util.concurrent.FutureTask 
| 1110 | runWorker . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor 
| 603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . . . . . . . . . . in java.lang.Thread 

回答

2

望着CXF插件信息頁面,我發現這一點:

Note that any classes being returned or passed as parameters 
    must be annotated with @XmlAccessorType(XmlAccessType.FIELD) 

    @XmlAccessorType(XmlAccessType.FIELD) 
    class Person { 
     .... 
    } 

----- -----編輯此 一個困擾了我很多,因爲它應該是如此簡單。我不知道你是否懂了工作,但這裏是我必須做的:

package testcxf 
    import javax.xml.bind.annotation.* 

    @XmlRootElement(name="person") 
    @XmlAccessorType(XmlAccessType.NONE) 
    @XmlType(propOrder = ["name","city","age"]) 

    class Person { 
     @XmlElement 
     String name 

     @XmlElement 
     String city 

     @XmlElement 
     int age 

     static constraints = { 
     } 
    } 

這會讓你除了無任何XmlAccessorType收到了同樣的錯誤。然後爲了獲得可用的字段,我必須添加@XmlElement註釋。

現在,它在運行時錯誤和WSDL包含Person對象的細節:

<xs:element name="person" type="tns:person"/> 
    <xs:complexType name="person"> 
     <xs:sequence> 
     <xs:element minOccurs="0" name="name" type="xs:string"/> 
     <xs:element minOccurs="0" name="city" type="xs:string"/> 
     <xs:element name="age" type="xs:int"/> 
     </xs:sequence> 
    </xs:complexType> 
+0

我也碰到過這一點,但它似乎並沒有產生任何影響。即使在添加註釋之後,也會發生相同的異常。 –

+0

這個調整適合我,謝謝。我有點困惑,至於爲什麼這是必要的,我搜索的每個論壇條目都只是簡單地說添加@XmlAccessorType(XmlAccessor.FIELD)來解決這個問題。我希望這只是CXF版本的一個小故障,但誰知道呢。 –

+0

它絕對聽起來像一個錯誤。沒有任何我能夠找到的東西除了FIELD以外沒有其他字符... – Kelly

相關問題