gpt4 book ai didi

java - 严重 : Could not dispatch event: Eventbus com. google.common.eventbus.SubscriberExceptionContext

转载 作者:IT老高 更新时间:2023-10-28 13:49:47 26 4
gpt4 key购买 nike

对于 EventBus,我将代码合并到我的 java Spring 应用程序中并完全控制它,但结果没有改变。

当我在 spring sts (javaw) 中运行 EventBus 时,没有问题,但是当我使用 java -jar project.jar 在服务器中运行时,它给出了相同的严重:无法调度事件:错误

以下内容对我不起作用..

package edu.uams.event;

import java.awt.EventQueue;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.Executor;

import org.apache.log4j.Logger;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventHandler;
import com.google.common.eventbus.SubscriberExceptionHandler;


import edu.uams.domain.TirEvent;
import edu.uams.pacs.IncomingFileMonitor;

public class AysncTraumaEventBus extends AsyncEventBus {

private final static Logger logger = Logger.getLogger(AysncTraumaEventBus.class);
private String name = null;

public AysncTraumaEventBus(Executor executor,
SubscriberExceptionHandler subscriberExceptionHandler) {
super(executor, subscriberExceptionHandler);

logger.info("AysncTraumaEventBus created.");
}

public AysncTraumaEventBus(String name, Executor executor) {
super(name,executor);
this.name=name;
logger.info("AysncTraumaEventBus created. Name:"+this.name);
}

@Override
public void register(Object object) {
super.register(object);
}

@Override
public void unregister(Object object) {
super.unregister(object);
}

@Override
public void dispatch(Object event, EventHandler wrapper) {
try {
logger.info("Let's dispatch Aysnchroneous Trauma Event:"+ ((TirEvent) event).getResultMessage());
wrapper.handleEvent(event);
} catch (InvocationTargetException e) {
// My logger
logger.error("Could not dispatch event: " + event + " to handler " + wrapper+" e:"+e.getMessage());
logger.info("Lets try to disptach again!");
super.post(new ExceptionEvent(event, e));
}
}


public static final class ExceptionEvent {
public final Object event;
public final InvocationTargetException exception;

public ExceptionEvent(final Object event, final InvocationTargetException exception) {
this.event = event;
this.exception = exception;
}
}

}

EventHandler 无法调用目标事件..

wrapper.handleEvent(事件);

当你查看包装器(EventHandler)时:

public void handleEvent(Object event) throws InvocationTargetException {
checkNotNull(event);
try {
method.invoke(target, new Object[] { event });
} catch (IllegalArgumentException e) {
throw new Error("Method rejected target/argument: " + event, e);
} catch (IllegalAccessException e) {
throw new Error("Method became inaccessible: " + event, e);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof Error) {
throw (Error) e.getCause();
}
throw e;
}
}

你看到了 method.invoke(target, new Object[] { event });从 Method.class 抛出 InvocationTargetException

public Object invoke(Object obj, Object... args)
throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException
{
if (!override) {
if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
Class<?> caller = Reflection.getCallerClass(1);

checkAccess(caller, clazz, obj, modifiers);
}
}
MethodAccessor ma = methodAccessor; // read volatile
if (ma == null) {
ma = acquireMethodAccessor();
}
return ma.invoke(obj, args);
}

不知何故它不能调用.. 但最有趣的部分是同一个 jar 文件和 EventBus 可以在 STS Run (javaw) 中正常运行但是当我从命令行运行 java 作为 java -jar project.jar 它可以't dispatch the event..

最佳答案

@Subscribe
@AllowConcurrentEvents
public void receivedDicomFile(TirEvent event){

try {



} catch (ClassNotFoundException e) {
logger.error(e.getMessage());
} catch (SQLException e) {
logger.error(e.getMessage());
} catch(Exception e){
logger.error(e.getMessage());
}



}

它总是需要 try catch 。感谢@dwnz 的帮助

关于java - 严重 : Could not dispatch event: Eventbus com. google.common.eventbus.SubscriberExceptionContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25367566/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com