2012-02-16 7 views
0

cxfプラグインを使用せずにcxfフレームワークを統合する方法を知っている人はいますか?私はすでにシンプルなサービスを公開していますが、問題は既存のgrailsサービスBeanをcxf jaxws beanに注入することです。grailsのネイティブCXF統合

applicationContext.xmlをiにおいては、次の定義に

<jaxws:server id="jaxwsService" serviceClass="at.pdts.cxf.HelloWorld" address="/hello"> 
    <jaxws:serviceBean> 
     <bean class="at.pdts.cxf.HelloWorldImpl"> 
      <property name="halloService"><ref bean="helloWorld"></ref></property> 
     </bean> 
    </jaxws:serviceBean> 
    </jaxws:server> 

を使用していたHelloWorld Beanは、通常のGrails serivceクラスです。起動時に私は次の例外を取得します。

bean 'helloWorld'への参照を解決できません。 プロパティ 'halloService';入れ子の例外org.springframework.beans.factory.NoSuchBeanDefinitionExceptionです。 'のhelloWorld' という名前のBeanが定義されていない

applicationContext.xmlを

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:jaxws="http://cxf.apache.org/jaxws" 
     xsi:schemaLocation=" 
      http://cxf.apache.org/jaxws 
      http://cxf.apache.org/schemas/jaxws.xsd 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

    <import resource="classpath:META-INF/cxf/cxf.xml"/> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> 


    <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean"> 
     <description>Grails application factory bean</description> 
     <property name="grailsDescriptor" value="/WEB-INF/grails.xml" /> 
     <property name="grailsResourceLoader" ref="grailsResourceLoader" /> 
    </bean> 

    <bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean"> 
     <description>A bean that manages Grails plugins</description> 
     <property name="grailsDescriptor" value="/WEB-INF/grails.xml" /> 
     <property name="application" ref="grailsApplication" /> 
    </bean> 

    <bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator"> 
     <constructor-arg> 
      <ref bean="grailsApplication" /> 
     </constructor-arg> 
     <property name="pluginManager" ref="pluginManager" /> 
    </bean> 

    <bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean"> 
     <property name="grailsResourceHolder" ref="grailsResourceHolder" /> 
    </bean> 

    <bean id="grailsResourceHolder" scope="prototype" class="org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder"> 
     <property name="resources"> 
       <value>classpath*:**/grails-app/**/*.groovy</value> 
     </property> 
    </bean>  

    <bean id="characterEncodingFilter" 
     class="org.springframework.web.filter.CharacterEncodingFilter"> 
     <property name="encoding"> 
      <value>utf-8</value> 
     </property> 
    </bean> 

    <jaxws:server id="jaxwsService" serviceClass="at.pdts.cxf.HelloWorld" address="/hello"> 
    <jaxws:serviceBean> 
     <bean class="at.pdts.cxf.HelloWorldImpl"> 
      <property name="halloService"><ref bean="halloService"></ref></property> 
     </bean> 
    </jaxws:serviceBean> 
    </jaxws:server> 

</beans>  

HelloWorldImpl.groovy

package at.pdts.cxf 

import javax.jws.WebService 

@WebService(endpointInterface = "at.pdts.cxf.HelloWorld") 
public class HelloWorldImpl implements HelloWorld { 

    def halloService // inject HelloService. Initialize this bean via applicationContext.xml 

    public String sayHi(String text) { 
     return "hello " + halloService.scream(text) 
    } 
} 

HelloService.groovy

class HalloService implements InitializingBean{ 

static transactional = false 

String scream(String text) { 
    text.toUpperCase() 
} 

// methods gets not called, so service bean is not initialized at the ws creation time 
void afterPropertiesSet() { 

    println "------> initializing bean HalloSerivce <-------- 
} 

}

jaxwsServiceの初期化時に、helloWorldサービスBeanは使用できないようです。

+0

「HelloWorldImpl」のオブジェクト「halloService」は、「HelloWorld」というクラスのインスタンスですか? –

+0

いいえ、halloSerivceはgrailsサービスの成果物です。私は私の質問にサービスクラスのコードを追加しました。 – hitty5

答えて

0

私はこれは私があなたの質問を読んで、初めてを逃したが、あなたはapplicationContext.xmlであなたのBeanを定義しています。あなたの質問のテストケースを作成していたとき、私はbean定義をgrails-app/conf/spring/resources.xmlに入れていました。そのファイルを作成し、その中に次を入れてみてください:サイドノートとして

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xsi:schemaLocation=" 
     http://cxf.apache.org/jaxws 
     http://cxf.apache.org/schemas/jaxws.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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 the bean for the service, link to groovy service bean --> 
    <jaxws:server id="jaxwsService" serviceClass="at.pdts.cxf.HelloWorld" address="/hello"> 
     <jaxws:serviceBean> 
      <bean class="at.pdts.cxf.HelloWorldImpl"> 
       <property name="halloService" ref="halloService" /> 
      </bean> 
     </jaxws:serviceBean> 
    </jaxws:server> 
</beans> 

、あなたはGrailsとCXF hereの統合に関する詳細な情報を見つけることができます。

+0

、あなたは完全に正しいです!プロパティはhalloService Beanを参照する必要があります。ひどいタイプミス。それでも私は同じエラーが発生しています。私の質問でわかるように、サービスクラスはInitializingBeanを実装して、サービスがフレームワークによっていつ初期化されるかを確認します。このメソッドは呼び出されません! – hitty5

+0

あなたはそのタイプミスを修正しても問題は残っているので、問題はあなたのBeanを定義する場所だと思います。私は新しい情報で私の答えを更新しました。 –

+0

resources.xmlファイル内のcxf serivce beanを定義することは、そのトリックでした。この時点でhalloService beanはすでに初期化されており、余分なbean定義は必要ないと思われます。 – hitty5

2

これは何かを指し示す必要があります。エラーが春は今エイリアス「のhelloWorldと春の豆を見つけることができることを意味することに

<bean id="helloWorld" class="at.pdts.cxf.HalloServiceImpl" /> 

<ref bean="helloWorld"> 

あなたは、この定義されたようなものを持っていますか。 "

spring.xml全体とjavaコードをHelloWorldImplに投稿すると便利でしょう。

EDIT:あなたの設定は自分の理論を確認します。

<ref bean=には「ここに何か他のものを注入する」と記載されています。しかし、あなたはそのBeanを定義していないので、No Bean定義は例外です。さらに、空の文字列を返すカスタムの叫びメソッドを使用してHalloService(HalloServiceImpl)の独自の実装を作成することで、コードを動作させることができました。 <bean id="helloWorld" class="at.pdts.cxf.HalloServiceImpl" />

EDIT#2:それを動作させるための別の方法は、HalloServiceを排除することである:

<jaxws:server id="jaxwsService" serviceClass="at.pdts.cxf.HelloWorld" address="/hello"> 
    <jaxws:serviceBean> 
     <bean class="at.pdts.cxf.HelloWorldImpl" /> 
    </jaxws:serviceBean> 
    </jaxws:server> 

</beans> 

HelloWorldImpl.groovy 

package at.pdts.cxf 

import javax.jws.WebService 

@WebService(endpointInterface = "at.pdts.cxf.HelloWorld") 
public class HelloWorldImpl implements HelloWorld { 


    public String sayHi(String text) { 
     return "hello scream!" + text 
    } 
} 

基本的に選択肢は次のとおりです。春HalloServiceのimplmentation、またはドンを提供それから私は、春の構成にこれを追加しましたそれをあなたのSpring.xmlで参照しないでください。

EDIT#3:InitializingBeanの目的の周りの誤解があります:

のjavadocから:

InitializingBeanインタフェースは に必要な豆で実装するには、一度すべてのプロパティを反応させますBeanFactory: の例でカスタム初期化を実行するか、単に のすべての必須プロパティが設定されているかどうかを確認するために設定されています。

InitializingBeanを実装することは、afterPropertiesSet()が呼び出されることを意味します。それはではなく、を意味します。つまり、Springは自動的にこのBeanをSpring Configに追加します。あなたはまだこのラインを使って春の構成でBeanを宣言する必要があります。

<bean id="halloService" class="at.pdts.cxf.HalloService" /> 
+0

ありがとうございます。しかし、私の問題は、jaxws serivce initの瞬間に、サービスビーン "helloWorld"は利用できません。これは、grailsの後半でsericeアーチファクトが発生するためです。 – hitty5

+0

私はあなたが私の反応を理解しているかどうかはわかりません。私が提案したアイテムを投稿することはできますか? –

+0

私は要求されたアイテムを提供しました。あなたが好きなら、私はgrailsプロジェクトのサンプルを提供することもできます。 – hitty5

関連する問題