Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Springbean创建错误_Java_Spring - Fatal编程技术网

Java Springbean创建错误

Java Springbean创建错误,java,spring,Java,Spring,所以我一直在关注Spring文档,特别是这一部分 在依赖注入上,但每当我的代码运行时,我都会得到一个关于bean创建的错误 这是我的部分代码,我试图以ExampleBean示例为基础 public class TimeFeedHandler implements MessageListener { String msgID = null; TimeBayeuxService timeBayeuxService; public void setTimeBaye

所以我一直在关注Spring文档,特别是这一部分

在依赖注入上,但每当我的代码运行时,我都会得到一个关于bean创建的错误

这是我的部分代码,我试图以ExampleBean示例为基础

public class TimeFeedHandler implements MessageListener {

    String msgID = null;

    TimeBayeuxService timeBayeuxService;

        public void setTimeBayeuxService(TimeBayeuxService timeBayeuxService) {
            this.timeBayeuxService = timeBayeuxService;
        }
我的SpringXML文件如下所示

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

<bean id="timeFeedHandler" class="com.example.streaming.time.TimeFeedHandler" >
<property name="timeBayeuxService" ref="timeBayeuxService"> </property>
</bean>
知道我做错了什么吗

编辑,这是TimeBayeuxService bean

<!-- 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类的一部分

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);

}

timeeedhandler
依赖于
timeBayeuxService
。由于NullPointerException,它无法初始化
timeBayeuxService
,因此spring无法注入bean

根据错误消息,
com.example.streaming.time.TimeBayeuxService
的构造函数中发生了NullPointerException。您如何创建
common.bayeux
bean?请粘贴
TimeBayeuxService
类的构造函数代码。它是一个接口吗?然后,您应该将实现类放入bean定义中

NPE的可能位置。如果没有完整的堆栈跟踪,我必须猜测以下代码行:

  • 它可以发生在超类的构造函数中
  • 这两种方法:
    LogServlet.addLogGatherer(logGatherer);startThread(fbayeux,testMsgTS,true)

  • timeeedhandler
    依赖于
    timeBayeuxService
    。由于NullPointerException,它无法初始化
    timeBayeuxService
    ,因此spring无法注入bean

    根据错误消息,
    com.example.streaming.time.TimeBayeuxService
    的构造函数中发生了NullPointerException。您如何创建
    common.bayeux
    bean?请粘贴
    TimeBayeuxService
    类的构造函数代码。它是一个接口吗?然后,您应该将实现类放入bean定义中

    NPE的可能位置。如果没有完整的堆栈跟踪,我必须猜测以下代码行:

  • 它可以发生在超类的构造函数中
  • 这两种方法:
    LogServlet.addLogGatherer(logGatherer);startThread(fbayeux,testMsgTS,true)


  • TimeBayeuxService是一个接口,您有一个接口的实现?您能检查包名是否正确吗
    com.example.streaming.time
    ?还为
    timeBayeuxService
    添加bean定义。为了正确的编码-make
    timeBayeuxService
    private这是您收到的唯一错误消息吗?对我来说,它看起来相当不完整。是的,我有一个TimeBayeux的实现。我删掉的错误消息非常长,让我编辑它,我会在一个位中发布它。TimeBayeuxService是一个接口,您有一个实现吗?您能检查您的包名是否正确
    com.example.streaming.time
    ?还为
    timeBayeuxService
    添加bean定义。为了正确的编码-make
    timeBayeuxService
    private这是您收到的唯一错误消息吗?对我来说,它看起来相当不完整。是的,我有一个TimeBayeux的实现。我删掉的错误消息非常长,让我编辑它,我会在一个小帖子中发布。添加了更多错误。添加的代码:)非常感谢您花这么多时间到目前为止CoolBeans,我非常感谢。:)@soulesschild-在你的构造函数中有很多地方可能会发生NPE。你看到NPE出现在堆栈跟踪中的哪一行了吗?堆栈跟踪显示,
    在com.example.streaming.common.SomeBayeuxService.(SomeBayeuxService.java:33)在com.example.streaming.time.TimeBayeuxService.(TimeBayeuxService.java:22)
    第22行是
    super(bayeux,TimeBayeuxService.class.getName())我正试图找到SomeBayeuxService的源代码,因为它是从Maven以一种简单的方式提取出来的JAR@soulesschild-这是堆栈跟踪中NullPointerException消息之后的第一行吗?如果是这样的话,那么您需要了解SomeBayeuxService.java类第33行上发生了什么。感谢您帮助我解决CoolBeans,我将通过堆栈跟踪和类来查看是否无法解决它:)也有一些高级开发人员帮我解决(我是一名正在接受培训的开发人员:))添加了代码:)非常感谢您花这么多时间来看CoolBeans,我很感激。:)@soulesschild-在你的构造函数中有很多地方可能会发生NPE。你看到NPE出现在堆栈跟踪中的哪一行了吗?堆栈跟踪显示,
    在com.example.streaming.common.SomeBayeuxService.(SomeBayeuxService.java:33)在com.example.streaming.time.TimeBayeuxService.(TimeBayeuxService.java:22)
    第22行是
    super(bayeux,TimeBayeuxService.class.getName())我正试图找到SomeBayeuxService的源代码,因为它是从Maven以一种简单的方式提取出来的JAR@soulesschild-这是堆栈跟踪中NullPointerException消息之后的第一行吗?如果是这样的话,那么您需要了解SomeBayeuxService.java类第33行上发生了什么。感谢您帮助我解决CoolBeans,我将通过堆栈跟踪和类来查看是否无法解决它:)也有一些高级开发人员帮助我(我是一名培训中的开发人员:)
    
    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)
    
    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);
    
    }