猿问

使用 Spring Boot 和 Wicket Authenticated过滤注册

我目前正在玩 Apache Wicket 8 和 Spring Boot。我制作了一个简单的网络应用程序,其中包含一些面板、面包屑数据提供程序等。该应用程序运行良好。在我的 Spring 配置类中,我设置了一个 Filter Bean。现在我想实现身份验证功能。因此,我从扩展 Wickets WebApplication 类切换到 AuthenticatedWebApplication 类,并创建了一个自定义的 AuthenticatedWebSession。


当我现在启动应用程序时,我收到一个WicketRuntimeException告诉我使用Application.init()方法来配置我的应用程序对象的消息。由于某种原因,无法再实例化我的 Filter Bean。


我尝试使用 aFilterRegistrationBean而不是Filter具有相同的效果。


对于如何解决这个问题,有任何的建议吗?


这是我的配置类FilterRegistrationBean:


@Configuration

@Import({PersistenceConfig.class})

public class SpringConfig {


// Either using Filter or FilterRegistrationBean is not working anymore


//  @Bean

//  public Filter getWicketFilter() {

//      WicketApplication webApplication = new WicketApplication();

//          webApplication.setConfigurationType(RuntimeConfigurationType.DEVELOPMENT);

//      WicketFilter filter = new WicketFilter(webApplication);

//      filter.setFilterPath("/");

//      return filter;

//

//  }


@Bean

public FilterRegistrationBean<WicketFilter> wicketFilterRegistration(){

    WicketApplication webApplication = new WicketApplication();

        webApplication.setConfigurationType(RuntimeConfigurationType.DEVELOPMENT);


        WicketFilter filter = new WicketFilter(webApplication);

        filter.setFilterPath("/");


        FilterRegistrationBean<WicketFilter> registration = new FilterRegistrationBean<>();

        registration.setFilter(filter);

            registration.addInitParameter(WicketFilter.APP_FACT_PARAM,SpringWebApplicationFactory.class.getName());

        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD);


    return registration;

}


}


交互式爱情
浏览 129回答 3
3回答

慕标琳琳

您应该在 FilterRegistrationBean 定义中执行此操作,即:@Beanpublic FilterRegistrationBean<WicketFilter> wicketFilterRegistration(){WicketApplication webApplication = new WicketApplication();    webApplication.setConfigurationType(RuntimeConfigurationType.DEVELOPMENT);webApplication.init();//HERE!顺便说一句:考虑使用最新的 8.x 版本,即 8.5.0

蝴蝶刀刀

由于异常消息表明您需要在实例化后调用 application.init() 。

慕容708150

不幸的是,您的解决方案没有奏效。再次抛出同样的错误。但是我最终能够确定问题所在。问题出在我的 Wicket Application 类的构造函数中。在这个构造函数中,我调用了 super.init()。删除此应用程序后启动时没有 Bean 实例化错误。public class WicketApplication extends AuthenticatedWebApplication {//&nbsp; This caused the problem with instatiating the FilterRegistrationBean&nbsp; &nbsp;&nbsp;//&nbsp; public WicketApplication() {//&nbsp; &nbsp; &nbsp; super.init();//&nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; protected void init() {&nbsp; &nbsp; &nbsp; &nbsp; super.init();&nbsp; &nbsp; &nbsp; &nbsp; getComponentInstantiationListeners().add(new SpringComponentInjector(this));&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; mountPage("/admin", AdminPage.class);&nbsp; &nbsp; &nbsp; &nbsp; mountPage("/login", LoginPage.class);&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; public Class<? extends Page> getHomePage() {&nbsp; &nbsp; &nbsp; &nbsp; return AdminPage.class;&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; protected Class<? extends AbstractAuthenticatedWebSession> getWebSessionClass() {&nbsp; &nbsp; &nbsp; &nbsp; return AppAuthenticatedWebSession.class;&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; protected Class<? extends WebPage> getSignInPageClass() {&nbsp; &nbsp; &nbsp; &nbsp; return LoginPage.class;&nbsp; &nbsp; }&nbsp; &nbsp; public static WicketApplication get() {&nbsp; &nbsp; &nbsp; &nbsp; return (WicketApplication) Application.get();&nbsp; &nbsp; }}
随时随地看视频慕课网APP

相关分类

Java
我要回答