【发布时间】:2015-01-14 15:45:24
【问题描述】:
我在自己制作的罐子里有一个枚举。这个 jar 是第二个 jar 的依赖项,它使用枚举值。
现在,第二个 jar 是日志框架,而本例中的第一个 jar 是日志框架的模型类。
我正在尝试将此日志框架实现到我制作的 Web 应用程序中。长话短说,它仍然需要一些工作,但我被困在一个问题上。框架配置初始化中的错误被捕获为异常,并调用方法。此方法有一个 Enum 值作为其参数之一。但是,我在这个枚举上得到了 java.lang.NoSuchFieldError。
枚举值是错误的,所以我认为这可能是巧合。但是当我将其更改为 BABYLOVE 时,错误消息也发生了变化。
我已经检查了类/枚举名称中的冗余和/或可能的重叠,但我找不到。
顺序:
- Web App 调用初始化日志框架(直接依赖)
- logging-framework 在加载自己的配置时出现问题,并引发异常
- 异常处理,调用方法注册错误
- 使用多个参数调用该方法,其中一个是来自 logging-framework-model.jar 的枚举值,它是 Web 应用程序的传递依赖项
-
网络应用引发异常
java.lang.NoSuchFieldError: BABYLOVE at logging.framework.Constants.<clinit>(Constants.java:52) at logging.framework.Logger.<init>(Logger.java:60) at logging.framework.LogContext.getLoggerFromContext(LogContext.java:95) at logging.framework.LogContext.getCurrent(LogContext.java:48) at action.navigation.CalendarElementEditorAction.execute(CalendarElementEditorAction.java:39) Truncated. see log file for complete stacktrace
常量,第 51-52 行:
public static final Event ConfigValidationFailed =
EventLogHelper.getEvent(EventLogSource.LoggingFramework, EventLogEntryType.BABYLOVE");
EventLogEntryType:
@XmlType(name = "EventLogEntryType")
@XmlEnum
public enum EventLogEntryType {
//for test purposes, should be removed. This variable is given a name that can not be confused with standard names in error messages, like Error and Warning can.
@XmlEnumValue("BabyLove")
BABYLOVE("BabyLove"),
@XmlEnumValue("Error")
ERROR("Error"),
@XmlEnumValue("Warning")
WARNING("Warning"),
@XmlEnumValue("Information")
INFORMATION("Information"),
@XmlEnumValue("SuccessAudit")
SUCCESSAUDIT("SuccessAudit"),
@XmlEnumValue("FailureAudit")
FAILUREAUDIT("FailureAudit");
private final String value;
EventLogEntryType(String v) {
value = v;
}
public String value() {
return value;
}
public static EventLogEntryType fromValue(String v) {
for (EventLogEntryType c: EventLogEntryType .values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
我不知道这是否重要,但我正在使用 maven2 来处理我的依赖关系。
【问题讨论】:
-
BaybLove 哈哈!也意味着 - 在
EventLogEntryType上似乎仍然是一个类重叠。您是否尝试过像EventLogHelper.getEvent(EventLogSource.LoggingFramework, the.full.package.name.EventLogEntryType.BABYLOVE")那样明确地将包名称放在那里 -
猜猜我在听哪首歌 ;)。我马上试试
-
不,抱歉。同样的错误。
-
找到了!我的 Web 应用程序有另一个依赖项,即我创建的一组基类。该 jar 再次将 logging-jars 作为依赖项,只有以前的版本。打开 jar 并检查它打包的日志罐的版本后,我注意到了错误。
标签: java web-applications enums weblogic11g nosuchfieldexception