2011-09-09 7 views
1

だから私は春のドキュメント、特にこの部分を以下のしてきた、依存性注入ののSpring Beanの作成エラー

http://static.springsource.org/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-collaboratorsが、私のコードが実行されるたびに、私は豆の作成に関するエラーが発生します。

ここで私はExampleBean例を下地オフしようとした私のコードの部分があり、

public class TimeFeedHandler implements MessageListener { 

    String msgID = null; 

    TimeBayeuxService timeBayeuxService; 

     public void setTimeBayeuxService(TimeBayeuxService timeBayeuxService) { 
      this.timeBayeuxService = timeBayeuxService; 
     } 

そして、私の春のXMLファイルは、次のようになり、

<!-- A POJO that implements the JMS message listener --> 

<bean id="timeFeedHandler" class="com.example.streaming.time.TimeFeedHandler" > 
<property name="timeBayeuxService" ref="timeBayeuxService"> </property> 
</bean> 

私が得るエラーは、

です
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeFeedHandler' defined in URL.... 

私が間違っている理由は何ですか?

編集は、ここではここで、

<!-- Time BayeuxServices --> 

<bean id="timeBayeuxService" class="com.example.streaming.time.TimeBayeuxService" lazy-init="true"> 
    <constructor-arg><ref bean="common.bayeux" /></constructor-arg> 
    <property name="timeBean" ref="time.time" /> 
</bean> 

TimeBayeuxService Beanでエラーの詳細です。 STSからの完全なエラーログは長すぎます。私はTimeBayeuxService Beanを正しく参照していないようですが、論理的に私が間違っていることを見ることはできません。ここ

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeFeedHandler' defined in URL [file:/Users/nullpoint/applicationContext.xml]: Cannot resolve reference to bean 'timeBayeuxService' while setting bean property 'timeFeedHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeBayeuxService' defined in URL [file:/Users/nullpoint/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.example.streaming.time.TimeBayeuxService]: Constructor threw exception; nested exception is java.lang.NullPointerException 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) 

はTimeBayeuxServiceクラスの部分

public class TimeBayeuxService { 

private Bayeux bayeux; 
private static StreamingTimeLogGatherer logGatherer; 
String testMsgTS = "This is a test message from the original service"; 

public TimeBayeuxService(Bayeux bayeux) extends SomeBayeuxService{ 
    super(bayeux, TimeBayeuxService.class.getName()); 

    this.bayeux = bayeux; 
    final Bayeux fbayeux = bayeux; 

    this.logGatherer = logGatherer; 
    LogServlet.addLogGatherer(logGatherer); 

    startThread(fbayeux, testMsgTS, true); 

} 
+0

TimeBayeuxServiceが一つのインタフェースであり、あなたがそれの一つの実施がありますか? –

+0

あなたのパッケージ名が 'com.example.streaming.time'であることを確認できますか? 'timeBayeuxService'にBean定義を追加してください。適切なコーディングを行うには、 'timeBayeuxService' private – CoolBeans

+1

それが唯一のエラーメッセージですか?それは私にはむしろ不完全に見えます。 – Friek

答えて

1

timeFeedHandlertimeBayeuxService依存性を有しています。それはNullPointerExceptionのためにtimeBayeuxServiceを初期化することができないので、springはBeanを挿入できません。

エラーメッセージによると、NullPointerExceptionがコンストラクタcom.example.streaming.time.TimeBayeuxServiceで発生しました。どのようにしてcommon.bayeux beanを作成していますか? TimeBayeuxServiceクラスのコンストラクタコードを貼り付けてください。それはインターフェイスですか?次に、実装クラスをBean定義に配置する必要があります。

NPEの可能な場所。完全なスタックトレースがなければ、次のコード行を推測する必要があります。

  1. スーパークラスのコンストラクタ内で発生する可能性があります。
  2. これらの2つの方法:LogServlet.addLogGatherer(logGatherer); startThread(fbayeux, testMsgTS, true);
+0

コードを追加しました: クールビーンズの時間を借りてくれてありがとう、私はそれを感謝します。 :) –

+0

@soulesschild - あなたのコンストラクタでNPEが発生する可能性がある場所がいくつかあります。 NPEがスタックトレースで発生した行を確認できますか? – CoolBeans

+0

スタックトレースは、 at com.exampleと表示されます。streaming.common.SomeBayeuxService。 (SomeBayeuxService.java:33) \t(com.example.streaming.time.TimeBayeuxService)。 (TimeBayeuxService.java:22) ' ライン22は 'スーパー(バイユー、TimeBayeuxService.class.getName())である; ' それが引っ張られます何かのように私はSomeBayeuxServiceのソースコードを見つけようとしていますJARのMavenから –

関連する問題