2017-05-06 25 views
0

私はSpring Integrationフレームワークが初めてで、基本的な例を実装しようとしましたが、NULLポインタ例外を取得しようとしました。SpringインテグレーションでnullPointerExceptionが発生する

統合spring.xml

<int:gateway service-interface="com.fil.MyService" default-request- 
channel="in"/> 
<int:chain input-channel="in"> 
    <int:transformer expression="'hello:'+payload"></int:transformer> 
    <int:service-activator> 
     <int-groovy:script> 
      <![CDATA[println "processing"+payload]]> 
     </int-groovy:script> 
     </int:service-activator> 
    </int:chain> 
    </beans> 

MyService.java

public interface MyService { 
void single(String foo); 
} 

Test.java

@ContextConfiguration(locations = { "/WEB-INF/integration-spring.xml" }) 
public class MyServiceTest { 

@Autowired 
private MyService service; 

@Test 
public void test() { 
    try{ 
     service.single("hELLO ");//Getting null pointer exception 
    } 
    catch(Exception e){ 
     e.printStackTrace(); 
    } 
}} 
+0

classServiceのどこかにMyServiceの実装がありますか?正しく注釈が付けられていますか? –

+1

適切に設定された場合、Spring Integrationフレームワークは、サービスインタフェースタイプ ''でプロキシBeanを作成します。メソッド引数を 'Message 'にラップし、 'channel'に送信します。テストクラスには、Springテストコンテキストフレームワークランナーがありません。 –

答えて

1

テストフレームワークは、あなたをロードするように、また、あなたのテストクラスに@Runwith(SpringJunit4ClassRunner.class)が必要アプリケーションコンテキストを生成し、テストクラスをオートワイヤリングする。

+0

それは働いた。サンクス.. !!! –

関連する問題