- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个这样定义的类:
public class MyClass extends SimpleChannelInboundHandler<DataFrame<ByteBuf>> implements ApplicationEventPublisherAware
(SimpleChannelInboundHandler 是一个 io.netty 类。)
然后,在我的 xml 文件中,我像这样定义 MyClass:
<bean id="MyClass" class="com.mypackage.MyClass" />
根据文档:
At configuration time, the Spring container will detect that EmailService implements ApplicationEventPublisherAware and will automatically call setApplicationEventPublisher().
但是当我运行这个时它是空的。
有什么想法吗?
谢谢
最佳答案
ApplicationEventPublisherAware
的常见使用模式看起来像这样:
package example;
import org.springframework.stereotype.*;
import org.springframework.context.*;
@Component
public class MyBean implements ApplicationEventPublisherAware {
ApplicationEventPublisher applicationEventPublisher;
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
System.out.println("publisher: " + applicationEventPublisher);
this.applicationEventPublisher = applicationEventPublisher;
}
... (use applicationEventPublisher in methods)
}
你只需要确保bean确实通过组件扫描/配置/<bean>
添加到上下文中标签,尝试将其注入(inject)到另一个 bean 中进行检查。
关于java - Spring 3.1.2 : ApplicationEventPublisher not being set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24291975/
我有一个下一个 customEventPublisher 类: @Component public class CustomEventPublisher { @Autowired private st
我需要使用事件驱动机制。使用ApplicationEventPublisher。我想在到达监听此事件的端点之前为消息设置延迟。有这样的办法吗?找到https://docs.spring.io/spri
我想使用 Spring Web Flow 步骤中的 ApplicationEventPublisher#publishEvent() 发布应用程序事件。发布者通常是应用程序上下文,但除非有必要(特别是
我正在尝试构建一个 DiscoveryClient,我希望它在路线发生更改时触发一个事件。我正在使用 publisher.publishEvent(new InstanceRegisteredEven
我有一个正在发布事件的 Controller @RestController public class Controller { @Autowired private Applicat
我有一个这样定义的类: public class MyClass extends SimpleChannelInboundHandler> implements ApplicationEventPub
我看到有很多实现,但是如何在不使用 Autowiring 和使用 xml 配置的情况下使用默认实现? 最佳答案 有多种选择,您可以使用注释、实现和接口(interface)或在 xml 或 java
我是一名优秀的程序员,十分优秀!