Spring ApplicationEventPublisherAware - 发布者未设置

时间:2014-10-30 18:06:09

标签: spring spring-mvc

使用 Spring Tool Suite版本3.6.1 创建网页。应用程序接收需要传播到UI的外部事件。

指向/找到有关 ApplicationEventPublisherAware (相关链接http://www.javacodegeeks.com/2012/08/observer-pattern-with-spring-events.htmlhttp://www.programmingforliving.com/2012/10/event-handling-in-spring.html的信息。)按照建议实施但 setApplicationEventPublisher ()方法没有被调用,所以发布者没有被设置。

该对象有一个默认的构造函数,据我所知,bean必须正确工作。出于测试目的,它还有另一个接受参数的公共构造函数。默认构造函数调用其他构造函数来完成其工作。我的代码片段是:

public class NodeObserver extends NodeObserverBase
implements ApplicationEventPublisherAware
{
  private ApplicationEventPublisher mPublisher;

  /** Default constructor using singleton items */
  public NodeObserver() {
    this(A.getInstance(), B.getInstance(), A.getInstance().getC());
  }
  public NodeObserver(final A a, final B b, final C c)
  {
    .....
  }
  .....
  public void setApplicationEventPublisher(
                final ApplicationEventPublisher publisher)
  {
    mPublisher = publisher;
  }
  .....
}

为什么没有调用set publisher方法的任何想法?链接讨论了如何更改bean属性,但我找不到任何带有XML XML的文件。

我做错了什么?非常感谢任何帮助。

Lori< *>

1 个答案:

答案 0 :(得分:0)

通过各种调查找到答案。

我把班级变成了一个控制器。那就是我将@Controller指令添加到类行之前:

@Controller
public class NodeObserver extends NodeObserverBase
implements ApplicationEventPublisherAware
{
  .....
}

Spring Tools负责其余部分。

干杯 Lori< *>