2012-05-02 25 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() 
    } 
} 

このサービスは期待どおりに機能し、テストクライアントは正常にエコーと逆のメソッドを呼び出しました。次に、簡単なドメインクラスPersonを作成しました。

そして、ドメインとやりとりするための基本的な機能を持つサービスを改訂しました。

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 { 
     .... 
    } 

は----- EDITは----- この1つは私をたくさん気に。私は、あなたが今まで得た場合、それが動作しますが、ここで私がやっていたものであるかわからない:

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 = { 
     } 
    } 

それはあなたがNONE以外の任意の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

関連する問題