Wicket 错误页面不工作

Wicket error pages not working

Wicket 中的错误页面存在问题。 我们使用 Wiket(8.0.0-M8) 和 spring security(4.2.3.RELEASE).

我知道如何设置我的错误页面,但标准页面也不起作用(我得到错误页面 tomcat,而不是我的)。

    getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
    getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);

特殊之处在于可以指定页面500(内部错误)。但其余的没有。

Spring Security 没有页面 403(拒绝访问页面),如果您在 spring 和 Wicket 中指定 mountPage,它将发送到 404。 如何声明 404 也不是很清楚。

更新:web.xml:

<display-name>project</display-name>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<filter>
    <filter-name>transactionFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
        <param-name>targetBeanName</param-name>
        <param-value>transactionFilter</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>transactionFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>wicket.project</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
        <param-name>applicationFactoryClassName</param-name>
        <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
    </init-param>
    <init-param>
        <param-name>applicationClassName</param-name>
        <param-value>ru.company.project.web.WicketApplication</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>wicket.project</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

以下是使用 Spring 启动的方法:

import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.servlet.ErrorPageRegistrar;
import org.springframework.boot.web.servlet.ErrorPageRegistry;
import org.springframework.http.HttpStatus;

public class MyErrorPageRegistrar implements ErrorPageRegistrar {
    @Override
    public void registerErrorPages(final ErrorPageRegistry registry) {
         registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,
              MyApplication.PAGE_NOT_FOUND_MOUNT_PATH));
    }
}

在MySpringConfiguration.java中:

@Bean
public ErrorPageRegistrar errorPageRegistrar(){
    return new MyErrorPageRegistrar();
}

在MyApplication.java中:

String PAGE_NOT_FOUND_MOUNT_PATH = "/not/found";   
...
@Override public void init() {
   super.init();
   ...
   mountPage(PAGE_NOT_FOUND_MOUNT_PATH, Error404Page.class);
}