Dropwizard の
エラー内容
ServerCommand の
Exception in thread "main" java.lang.IllegalStateException: Cannot figure out type parameterization for xxx.xxx.xxx.xxx.BatchApplication at io.dropwizard.util.Generics.getTypeParameter(Generics.java:62) at io.dropwizard.Application.getConfigurationClass(Application.java:30) at io.dropwizard.cli.ServerCommand.<init>(ServerCommand.java:25) at io.dropwizard.Application.run(Application.java:69) at xxx.xxx.xxx.xxx.BatchApplication.main(BatchApplication.java:38)
修正前の 記述
以下のように、
public class BatchApplication extends Application { public static void main(String[] args) throws Exception { new BatchApplication().run(args); } }
修正後の 記述
以下型指定を
public class BatchApplication extends Application<Configuration> { public static void main(String[] args) throws Exception { new BatchApplication().run(args); } }
エラーの 発生箇所に ついて
dropwizard/Application.java at master · dropwizard/dropwizard のApplication.getConfigurationClass
ではGenerics.getTypeParameter()
を
/** * Returns the {@link Class} of the configuration class type parameter. * * @return the configuration class * @see Generics#getTypeParameter(Class, Class) */ public Class<T> getConfigurationClass() { return Generics.getTypeParameter(getClass(), Configuration.class); }
Generics.getTypeParameter
では、
/** * Finds the type parameter for the given class which is assignable to the bound class. * * @param klass a parameterized class * @param bound the type bound * @param <T> the type bound * @return the class's type parameter */ public static <T> Class<T> getTypeParameter(Class<?> klass, Class<? super T> bound) { Type t = requireNonNull(klass); while (t instanceof Class<?>) { t = ((Class<?>) t).getGenericSuperclass(); } /* This is not guaranteed to work for all cases with convoluted piping * of type parameters: but it can at least resolve straight-forward * extension with single type parameter (as per [Issue-89]). * And when it fails to do that, will indicate with specific exception. */ if (t instanceof ParameterizedType) { // should typically have one of type parameters (first one) that matches: for (Type param : ((ParameterizedType) t).getActualTypeArguments()) { if (param instanceof Class<?>) { final Class<T> cls = determineClass(bound, param); if (cls != null) { return cls; } } else if (param instanceof TypeVariable) { for (Type paramBound : ((TypeVariable<?>) param).getBounds()) { if (paramBound instanceof Class<?>) { final Class<T> cls = determineClass(bound, paramBound); if (cls != null) { return cls; } } } } else if (param instanceof ParameterizedType) { final Type rawType = ((ParameterizedType) param).getRawType(); if (rawType instanceof Class<?>) { final Class<T> cls = determineClass(bound, rawType); if (cls != null) { return cls; } } } } } throw new IllegalStateException("Cannot figure out type parameterization for " + klass.getName()); }
throw new IllegalStateException("Cannot figure out type parameterization for " + klass.getName());
がこれで
以上です。
コメント