java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:721)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
at net.thucydides.core.steps.StepFactory.createProxyStepLibrary(StepFactory.java:155)
at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:109)
at net.thucydides.core.steps.StepFactory.instantiateNewStepLibraryFor(StepFactory.java:101)
at net.thucydides.core.steps.StepFactory.getStepLibraryFor(StepFactory.java:67)
at net.thucydides.core.steps.StepAnnotations.instantiateAnyUnitiaializedSteps(StepAnnotations.java:50)
at net.thucydides.core.steps.StepAnnotations.instanciateScenarioStepFields(StepAnnotations.java:41)
at net.thucydides.core.steps.StepAnnotations.injectScenarioStepsInto(StepAnnotations.java:23)
at net.thucydides.jbehave.ThucydidesStepFactory.createInstanceOfType(ThucydidesStepFactory.java:80)
at org.jbehave.core.steps.StepCreator.stepsInstance(StepCreator.java:82)
at org.jbehave.core.steps.StepCreator$ParameterisedStep.perform(StepCreator.java:550)
at org.jbehave.core.embedder.StoryRunner$FineSoFar.run(StoryRunner.java:499)
at org.jbehave.core.embedder.StoryRunner.runStepsWhileKeepingState(StoryRunner.java:479)
at org.jbehave.core.embedder.StoryRunner.runScenarioSteps(StoryRunner.java:443)
at org.jbehave.core.embedder.StoryRunner.runCancellable(StoryRunner.java:305)
at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:219)
at org.jbehave.core.embedder.StoryRunner.run(StoryRunner.java:180)
at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:229)
at org.jbehave.core.embedder.StoryManager$EnqueuedStory.call(StoryManager.java:201)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
问问题
1238 次
2 回答
2
Im not sure this problem was solved, but i managed to understand my problem:
java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
with following code:
public class CglibTest {
@Test
public void shouldCreateDynamicProxy() {
Enhancer enh = new Enhancer();
enh.setSuperclass(CgPlay.class);
enh.setCallback((FixedValue) () -> "fixedValueFromProxy");
CgPlay cgPlay = (CgPlay) enh.create();
System.out.println(cgPlay.fooStringPar(null));
}
class CgPlay {
public String fooStringPar(String s) {
return "fooStringPar";
}
}
}
It turned out, the CGLib had problem with CgPlay class, since it was a non-static member inner class. Making CgPlay class a static class, or non-memeber class solved issue.
于 2020-06-11T10:11:58.270 回答
0
你有一个类通过使用 super() 调用他实现的类的构造函数,其中没有参数。
您的超类没有没有任何参数的构造函数。
例子:
public class Cat implements Animal {
public Cat() {
super();
}
}
public class Animal {
final String name;
public Animal(String name) {
this.name = name;
}
}
Cat 类中的super()
将调用 Animal 类的不带参数的构造函数。Animal 类没有这样的构造函数,因此会抛出像你这样的错误。
如果您让像 Spring 这样的框架尝试自动装配一个没有无参数构造函数的对象,也可能会导致这种情况。
请分享抛出错误的课程。
于 2017-12-08T13:51:15.220 回答