[英]How to inject RequestScope bean in spring boot wicket application
In my Wicket page I have: 在我的Wicket页面中,我有:
@SpringBean
protected J2EContext j2EContext;
In Configuration I have: 在配置中,我有:
@Bean
@RequestScope
public J2EContext getWebContext() {
return new J2EContext(request, response, getSessionStore());
}
@Bean
public RequestContextListener requestContextListener() {
return new RequestContextListener();
}
application starts OK but when I go to home page I got exception: 应用程序启动正常,但是当我转到主页时出现异常:
Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:931)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:631)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:
329)
at net.sf.cglib.proxy.Enhancer.generate(Enhancer.java:492)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93)
at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91)
at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
when wicket want to inject J2EContext
bean. 当检票口想注入J2EContext
bean时。 I think this is because page is rendering before @RequestScope
create this bean. 我认为这是因为页面是在@RequestScope
创建此bean之前呈现的。 Any idea how to fix this problem ? 任何想法如何解决此问题?
to inject beans Wicket creates a proxy in two different ways: 注入bean Wicket以两种不同的方式创建代理:
Unfortunately cglib can not create proxy for classes without a default constructor. 不幸的是,如果没有默认构造函数,cglib无法为类创建代理。 There is however a third way that can solve the problem. 但是,存在第三种方法可以解决该问题。 Just add objenesis as dependency to your project and Wicket will use it instead of cglib. 只需将objenesis添加为项目的依赖项,Wicket将使用它代替cglib。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.