org.springframework.boot.web.server.ErrorPage Java Examples

The following examples show how to use org.springframework.boot.web.server.ErrorPage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MvcAutoConfiguration.java    From MaxKey with Apache License 2.0 6 votes vote down vote up
/**
 * 配置默认错误页面(仅用于内嵌tomcat启动时) 使用这种方式,在打包为war后不起作用.
 *
 * @return webServerFactoryCustomizer
 */
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
    return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
        @Override
        public void customize(ConfigurableWebServerFactory factory) {
            _logger.debug("WebServerFactoryCustomizer ... ");
            ErrorPage errorPage400 = 
                    new ErrorPage(HttpStatus.BAD_REQUEST, "/exception/error/400");
            ErrorPage errorPage404 = 
                    new ErrorPage(HttpStatus.NOT_FOUND, "/exception/error/404");
            ErrorPage errorPage500 = 
                    new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/exception/error/500");
            factory.addErrorPages(errorPage400, errorPage404, errorPage500);
        }
    };
}
 
Example #2
Source File: AdminfacesAutoConfiguration.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
/**
 * This {@link WebFragmentRegistrationBean} is equivalent to the
 * {@code META-INF/web-fragment.xml} of the {@code admin-template.jar}.
 *
 * @return adminTemplateWebFragmentRegistrationBean
 */
@Bean
public WebFragmentRegistrationBean adminTemplateWebFragmentRegistrationBean() {
	WebFragmentRegistrationBean bean = new WebFragmentRegistrationBean();

	bean.getContextParams().put("primefaces.THEME", "admin");

	bean.getErrorPages().add(new ErrorPage(HttpStatus.FORBIDDEN, "/403.xhtml"));
	bean.getErrorPages().add(new ErrorPage(AccessDeniedException.class, "/403.xhtml"));
	bean.getErrorPages().add(new ErrorPage(AccessLocalException.class, "/403.xhtml"));
	bean.getErrorPages().add(new ErrorPage(HttpStatus.NOT_FOUND, "/404.xhtml"));
	bean.getErrorPages().add(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.xhtml"));
	bean.getErrorPages().add(new ErrorPage(Throwable.class, "/500.xhtml"));
	bean.getErrorPages().add(new ErrorPage(ViewExpiredException.class, "/expired.xhtml"));
	bean.getErrorPages().add(new ErrorPage(OptimisticLockException.class, "/optimistic.xhtml"));

	bean.getListeners().add(AdminServletContextListener.class);

	return bean;
}
 
Example #3
Source File: ScooldServer.java    From scoold with Apache License 2.0 6 votes vote down vote up
/**
 * @return Error page registry bean
 */
@Bean
public ErrorPageRegistrar errorPageRegistrar() {
	return new ErrorPageRegistrar() {
		@Override
		public void registerErrorPages(ErrorPageRegistry epr) {
			epr.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not-found"));
			epr.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403"));
			epr.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401"));
			epr.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500"));
			epr.addErrorPages(new ErrorPage(HttpStatus.SERVICE_UNAVAILABLE, "/error/503"));
			epr.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400"));
			epr.addErrorPages(new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/error/405"));
			epr.addErrorPages(new ErrorPage(Exception.class, "/error/500"));
		}
	};
}
 
Example #4
Source File: SystemConfig.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
/**
 * for vue history mode
 *
 * @return
 */
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
    JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/index"));
    return factory;
}
 
Example #5
Source File: MyServletContainerCustomizationBean.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void customize(ConfigurableServletWebServerFactory container) {
    container.setPort(8084);
    container.setContextPath("/springbootapp");

    container.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
    container.addErrorPages(new ErrorPage("/errorHaven"));
}
 
Example #6
Source File: ServletConfig.java    From EasyReport with Apache License 2.0 5 votes vote down vote up
@Bean
public ConfigurableServletWebServerFactory containerCustomizer() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

    factory.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/customError/401"));
    factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/customError/403"));
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/customError/404"));
    factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/customError"));
    return factory;
}
 
Example #7
Source File: ErrorConfigurar.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
public void registerErrorPages(ErrorPageRegistry registry) {
	ErrorPage[] errorPages=new ErrorPage[3];
       errorPages[0]=new ErrorPage(HttpStatus.NOT_FOUND,"/404.do");
       errorPages[1]=new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/500.do");
       //errorPages[2]=new ErrorPage(HttpStatus.NOT_ACCEPTABLE,"/406.do");
       //errorPages[3]=new ErrorPage(org.apache.shiro.authz.AuthorizationException.class, "/403.do");	//优先根据此来进行排查。 先根据具体异常的类、再根据错误码
       errorPages[2]=new ErrorPage(org.springframework.web.multipart.MaxUploadSizeExceededException.class, "/406.do");	//
       
       
       registry.addErrorPages(errorPages);
}
 
Example #8
Source File: JboneErrorPageRegister.java    From jbone with Apache License 2.0 5 votes vote down vote up
@Override
public void registerErrorPages(ErrorPageRegistry errorPageRegistry) {
    ErrorPage e404 = new ErrorPage(HttpStatus.NOT_FOUND, "/errors/404.html");
    ErrorPage e500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/errors/500.html");

    ErrorPage ticketValidateError = new ErrorPage(TicketValidationException.class,"/errors/ticketValidateError.html");
    errorPageRegistry.addErrorPages(ticketValidateError,e404, e500);
}
 
Example #9
Source File: MVCConfiguration.java    From seed with Apache License 2.0 5 votes vote down vote up
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
    ErrorPage[] errorPages = new ErrorPage[2];
    errorPages[0] = new ErrorPage(HttpStatus.NOT_FOUND, "/WEB-INF/jsp/common/404.jsp");
    errorPages[1] = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/WEB-INF/jsp/common/500.jsp");
    registry.addErrorPages(errorPages);
}
 
Example #10
Source File: ErrorPagesConfig.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
   * 自定义异常处理路径
   *
   * @return
   */
  @Bean
  public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
      return factory -> {
	factory.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400"));
	factory.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401"));
	factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403"));
	factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"));
	factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500"));
	factory.addErrorPages(new ErrorPage(Throwable.class, "/error/500"));
};
  }
 
Example #11
Source File: TraderMainConfiguration.java    From java-trader with Apache License 2.0 5 votes vote down vote up
@Bean
public ConfigurableServletWebServerFactory webServerFactory()
{
    JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
    int port = ConfigUtil.getInt("/BasisService/web.httpPort", 10080);
    factory.setPort(port);
    factory.setContextPath("");
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
    factory.setSelectors(1);
    factory.setAcceptors(1);
    factory.setThreadPool(new ExecutorThreadPool(executorService()));
    return factory;
}
 
Example #12
Source File: TraderUMainConfiguration.java    From java-trader with Apache License 2.0 5 votes vote down vote up
@Bean
public ConfigurableServletWebServerFactory webServerFactory()
{
    JettyServletWebServerFactory factory = new JettyServletWebServerFactory();
    int port = ConfigUtil.getInt("/BasisService/web.httpPort", 10080);
    factory.setPort(port);
    factory.setContextPath("");
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html"));
    factory.setSelectors(1);
    factory.setAcceptors(1);
    factory.setThreadPool(new ExecutorThreadPool(executorService()));
    return factory;
}
 
Example #13
Source File: ErrorPageConfiguration.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
@Override
public void registerErrorPages(ErrorPageRegistry errorPageRegistry) {
  errorPageRegistry.addErrorPages(
      new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"),
      new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500")
  );
}
 
Example #14
Source File: MossApplication.java    From Moss with Apache License 2.0 5 votes vote down vote up
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
	return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
		@Override
		public void customize(ConfigurableWebServerFactory factory) {
			factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/index.html"));
			//factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/index.html"));
		}
	};
}
 
Example #15
Source File: ErrorPageConfig.java    From kvf-admin with MIT License 5 votes vote down vote up
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
    ErrorPage error400Page = new ErrorPage(HttpStatus.BAD_REQUEST, "/400");
    ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404");
    ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500");
    registry.addErrorPages(error400Page, error404Page, error500Page);
}
 
Example #16
Source File: ErrorPagesConfig.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * 自定义异常处理路径
 *
 * @return
 */
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
    return (container -> {
        ErrorPage error400Page = new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400");
        ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401");
        ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN, "/error/403");
        ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
        ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
        ErrorPage errorExPage = new ErrorPage(Throwable.class, "/error/500");
        container.addErrorPages(error400Page, error401Page, error403Page, error404Page, error500Page, errorExPage);
    });
}
 
Example #17
Source File: StartApplication.java    From start.spring.io with Apache License 2.0 5 votes vote down vote up
@Bean
public ErrorPageRegistrar errorPageRegistrar() {
	return (registry) -> {
		registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
		registry.addErrorPages(new ErrorPage("/error/index.html"));
	};
}
 
Example #18
Source File: ErrorPageConfiguration.java    From black-shop with Apache License 2.0 5 votes vote down vote up
@Override
public void registerErrorPages(ErrorPageRegistry errorPageRegistry) {
  errorPageRegistry.addErrorPages(
      new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"),
      new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500")
  );
}
 
Example #19
Source File: ErrorPagesConfig.java    From springboot-shiro with MIT License 5 votes vote down vote up
/**
 * 自定义异常处理路径
 *
 * @return
 */
@Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
    return factory -> {
        factory.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400"));
        factory.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401"));
        factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403"));
        factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"));
        factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500"));
        factory.addErrorPages(new ErrorPage(Throwable.class, "/error/500"));
    };
}
 
Example #20
Source File: TarocoAuthenticationApplication.java    From Taroco with Apache License 2.0 5 votes vote down vote up
/**
 * 解决vue-router history 模式下刷新页面的404问题
 */
@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
    return factory -> {
        ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html");
        factory.addErrorPages(error404Page);
    };
}
 
Example #21
Source File: WebConfig.java    From wetech-admin with MIT License 4 votes vote down vote up
@Bean
public ErrorPageRegistrar myErrorPageRegistrar() {
    return registry -> registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/index.html"));
}
 
Example #22
Source File: Application.java    From admin-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void customize(ConfigurableWebServerFactory factory) {
    factory.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400"));
    factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500"));
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"));
}
 
Example #23
Source File: SpringConfig.java    From spring-boot-start-current with Apache License 2.0 4 votes vote down vote up
@Override
public void registerErrorPages ( ErrorPageRegistry registry ) {
    registry.addErrorPages( new ErrorPage( HttpStatus.NOT_FOUND , "/404" ) );
    registry.addErrorPages( new ErrorPage( HttpStatus.UNAUTHORIZED , "/401" ) );
    registry.addErrorPages( new ErrorPage( Throwable.class , "/500" ) );
}
 
Example #24
Source File: CustomErrorStatusHandlingBean.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void customize(ConfigurableServletWebServerFactory factory) {
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not_found"));
    factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/internal_error"));
}
 
Example #25
Source File: ErrorSpringConfiguration.java    From promregator with Apache License 2.0 4 votes vote down vote up
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
	registry.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/errors/401.html"));
	registry.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/errors/500.html"));
}
 
Example #26
Source File: ServletConfig.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void customize(ConfigurableServletWebServerFactory factory) {
	factory.setPort(Integer.valueOf(BotSettings.PORT.get()));
	factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
}
 
Example #27
Source File: ServletConfig.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void customize(ConfigurableServletWebServerFactory factory) {
	factory.setPort(Integer.valueOf(BotSettings.PORT.get()));
	factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
}
 
Example #28
Source File: ErrorConfig.java    From White-Jotter with MIT License 4 votes vote down vote up
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
    ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html");
    registry.addErrorPages(error404Page);
}
 
Example #29
Source File: ServletConfig.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void customize(ConfigurableServletWebServerFactory factory) {
	factory.setPort(Integer.valueOf(BotSettings.PORT.get()));
	factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
}
 
Example #30
Source File: ServletConfig.java    From DisCal-Discord-Bot with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void customize(ConfigurableServletWebServerFactory factory) {
	factory.setPort(Integer.valueOf(BotSettings.PORT.get()));
	factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/"));
}