在 wicket 的 AuthenticatedWebSession 中启动 spring bean
Initiating spring bean in wicket's AuthenticatedWebSession
所以我试图在扩展 wicket 的 AuthenticatedWebSession 的 class 中启动 spring bean。
stakcoverflow 中有一些答案,但那些对我不起作用。
public class AuthWebSession extends AuthenticatedWebSession {
@SpringBean(name = "authenticationService")
private AuthenticationService authenticationService;
public AuthWebSession(Request request) {
super(request);
Injector.get().inject(this);
}
@Override
protected boolean authenticate(String username, String password) {
//authenticationService is null here as the spring bean did not initiate
authenticationService.auth(username, password);
}
...
}
authenticationService 保持为空,因为 spring bean 未启动。使用 wicket 版本 7.3.0
知道如何正确注入它吗?
这是正确的方法。在执行 Injector.get().inject(this);
之后,bean 应该是非空的。
我在当前的应用程序中使用相同的。又是 7.3.0.
这里有一些建议:
确保您的测试使用 YourWicketApplication,或者如果他们使用模拟应用程序,则确保配置 SpringComponentInjector。
确保 @SpringBean
是 Wicket-Spring 的一个,因为 Spring 5 还添加了具有该名称的注释。虽然我怀疑你是否使用了 Spring 5 个快照。
请创建一个可重现问题的迷你演示应用程序,我们将帮助调试它!
所以我试图在扩展 wicket 的 AuthenticatedWebSession 的 class 中启动 spring bean。
stakcoverflow 中有一些答案,但那些对我不起作用。
public class AuthWebSession extends AuthenticatedWebSession {
@SpringBean(name = "authenticationService")
private AuthenticationService authenticationService;
public AuthWebSession(Request request) {
super(request);
Injector.get().inject(this);
}
@Override
protected boolean authenticate(String username, String password) {
//authenticationService is null here as the spring bean did not initiate
authenticationService.auth(username, password);
}
...
}
authenticationService 保持为空,因为 spring bean 未启动。使用 wicket 版本 7.3.0
知道如何正确注入它吗?
这是正确的方法。在执行 Injector.get().inject(this);
之后,bean 应该是非空的。
我在当前的应用程序中使用相同的。又是 7.3.0.
这里有一些建议:
确保您的测试使用 YourWicketApplication,或者如果他们使用模拟应用程序,则确保配置 SpringComponentInjector。
确保
@SpringBean
是 Wicket-Spring 的一个,因为 Spring 5 还添加了具有该名称的注释。虽然我怀疑你是否使用了 Spring 5 个快照。
请创建一个可重现问题的迷你演示应用程序,我们将帮助调试它!