org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter Java Examples

The following examples show how to use org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter. 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: WebContext.java    From spring-data-solr-showcase with Apache License 2.0 6 votes vote down vote up
@Bean
public WebMvcConfigurerAdapter mvcViewConfigurer() {

	return new WebMvcConfigurerAdapter() {

		@Override
		public void addViewControllers(ViewControllerRegistry registry) {

			registry.addViewController("/").setViewName("search");
			registry.addViewController("/monitor").setViewName("monitor");
		}

		@Override
		public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
			argumentResolvers.add(new PageableHandlerMethodArgumentResolver());
		}
	};
}
 
Example #2
Source File: CORSConfiguration.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {

        @Override
        public void addCorsMappings(CorsRegistry registry) {
            // Add CORS header for all path in application
            registry
                    .addMapping("/**") //
                    .allowedOrigins("*") //
                    .allowedMethods("POST", "GET", "OPTIONS", "DELETE", "PUT", "PATCH", "HEAD") //
                    .maxAge(3600) //
                    .allowedHeaders("x-requested-with", "Content-Type", "accept", "Authorization") //
                    .exposedHeaders("Authorization", "Location") //
                    .allowCredentials(true);
        }
    };
}
 
Example #3
Source File: HswebAutoConfiguration.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
@Bean
public WebMvcConfigurer webMvcConfigurer(List<HandlerMethodArgumentResolver> handlerMethodArgumentResolvers) {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
            super.addArgumentResolvers(argumentResolvers);
            argumentResolvers.addAll(handlerMethodArgumentResolvers);
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new HandlerInterceptorAdapter() {
                @Override
                public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
                    //clear thread local
                    ThreadLocalUtils.clear();
                }
            });
        }
    };
}
 
Example #4
Source File: Application.java    From basic with MIT License 6 votes vote down vote up
@Bean
public WebMvcConfigurer webMvcConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addViewControllers(ViewControllerRegistry viewControllerRegistry) {

            // 首页默认加载web端
            viewControllerRegistry.addViewController("/").setViewName("/web/index.html");
            viewControllerRegistry.addViewController("/index.html").setViewName("redirect:/");

            // web首页
            viewControllerRegistry.addViewController("/web").setViewName("/web/index.html");

            // webapp首页
            viewControllerRegistry.addViewController("/webapp").setViewName("/webapp/index.html");

            viewControllerRegistry.setOrder(Ordered.HIGHEST_PRECEDENCE);
            super.addViewControllers(viewControllerRegistry);
        }
    };
}
 
Example #5
Source File: CORSConfiguration.java    From web-flash with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedHeaders("*")
                    .allowedMethods("*")
                    .allowedOrigins("*");
        }
    };
}
 
Example #6
Source File: MyConfiguration.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
  return new WebMvcConfigurerAdapter() {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
      registry.addMapping("/**");
    }
  };
}
 
Example #7
Source File: WebSecurityConfigurer.java    From chvote-protocol-poc with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedMethods("GET", "POST", "OPTIONS")
                    .allowedOrigins("*");
        }
    };
}
 
Example #8
Source File: MainApplication.java    From camunda-bpm-swagger with Apache License 2.0 5 votes vote down vote up
@Bean
WebMvcConfigurerAdapter webMvcConfigurerAdapter() {
  return new WebMvcConfigurerAdapter() {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
      registry.addRedirectViewController("/swagger", "/webjars/swagger-ui/3.1.4");
      super.addViewControllers(registry);
    }
  };
}
 
Example #9
Source File: AuthorizingHandlerAutoConfiguration.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "hsweb.authorize.two-factor", name = "enable", havingValue = "true")
@Order(100)
public WebMvcConfigurer twoFactorHandlerConfigurer(TwoFactorValidatorManager manager) {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new TwoFactorHandlerInterceptorAdapter(manager));
            super.addInterceptors(registry);
        }
    };
}
 
Example #10
Source File: AuthorizingHandlerAutoConfiguration.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public WebMvcConfigurer webUserTokenInterceptorConfigurer(UserTokenManager userTokenManager,
                                                          AopMethodAuthorizeDefinitionParser parser,
                                                          List<UserTokenParser> userTokenParser) {

    return new WebMvcConfigurerAdapter() {
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new WebUserTokenInterceptor(userTokenManager, userTokenParser, parser));
            super.addInterceptors(registry);
        }
    };
}
 
Example #11
Source File: KeycloakCORSConfiguration.java    From ola with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfiguration() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/api/**")
                    .allowedMethods(HttpMethod.GET.toString(), HttpMethod.POST.toString(),
                            HttpMethod.PUT.toString(), HttpMethod.DELETE.toString(), HttpMethod.OPTIONS.toString())
                    .allowedOrigins("*");
        }
    };
}
 
Example #12
Source File: RxJavaMvcAutoConfiguration.java    From rxjava-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer rxJavaWebMvcConfiguration() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
            if (handlers != null) {
                returnValueHandlers.addAll(handlers);
            }
        }
    };
}
 
Example #13
Source File: ApplicationConfiguration.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer securityWebMvcConfigurer() {
	return new WebMvcConfigurerAdapter() {
		@Override
		public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
			argumentResolvers.add(new CurrentUserHandlerMethodArgumentResolver(userService));
		}
	};
}
 
Example #14
Source File: CaptchaConfiguration.java    From java-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer captchaWebMvcConfigurer() {
	return new WebMvcConfigurerAdapter() {
		@Override
		public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
			BufferedImageHttpMessageConverter bufferedImageHttpMessageConverter = new BufferedImageHttpMessageConverter();
			if (converters.size() > 0) {
				converters.add(converters.size() - 1, bufferedImageHttpMessageConverter);
			} else {
				converters.add(bufferedImageHttpMessageConverter);
			}
		}
	};
}
 
Example #15
Source File: MainController.java    From OSTMap with Apache License 2.0 5 votes vote down vote up
/**
 * Global enable CORS for all mappings /api/**
 *
 * @return
 */
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/api/**");
        }
    };
}
 
Example #16
Source File: SearchBoxConfiguration.java    From searchbox-core with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer rxJavaWebMvcConfiguration(List<AsyncHandlerMethodReturnValueHandler> handlers) {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
            if (handlers != null) {
                returnValueHandlers.addAll(handlers);
            }
        }
    };
}
 
Example #17
Source File: CorsConfiguration.java    From pazuzu-registry with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry
                    .addMapping("/api/**")
                    .allowedOrigins(allowedOrigins)
                    .allowedMethods("GET", "PUT", "POST", "DELETE");
        }
    };
}
 
Example #18
Source File: TomcatConfiguration.java    From flowing-retail-old with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurerAdapter forwardToIndex() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            // forward requests index.htm (as we might have two spring boot tomcats running in the same JVM they can see each others resources
            // so we use different index files to avoid confusion
            registry.addViewController("/").setViewName(
                    "forward:/monitor.html");
        }
    };
}
 
Example #19
Source File: TomcatConfiguration.java    From flowing-retail-old with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurerAdapter forwardToIndex() {
  return new WebMvcConfigurerAdapter() {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
      // forward requests index.htm (as we might have two spring boot tomcats
      // running in the same JVM they can see each others resources
      // so we use different index files to avoid confusion
      registry.addViewController("/").setViewName("forward:/shop.html");
    }
  };
}
 
Example #20
Source File: KafDrop.java    From Kafdrop with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurerAdapter webConfig()
{
   return new WebMvcConfigurerAdapter()
   {
      @Override
      public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
      {
         super.configureContentNegotiation(configurer);
         configurer.favorPathExtension(false);
      }
   };
}
 
Example #21
Source File: WebConfig.java    From jee-universal-bms with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurerAdapter forwardToIndex() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController("/").setViewName("redirect:/home.html");
        }
    };
}
 
Example #22
Source File: Application.java    From springfox-demos with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
  return new WebMvcConfigurerAdapter() {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
      registry
          .addMapping("/api/pet")
          .allowedOrigins("http://editor.swagger.io");
      registry
          .addMapping("/v2/api-docs.*")
          .allowedOrigins("http://editor.swagger.io");
    }
  };
}
 
Example #23
Source File: CORSConfiguration.java    From EasyEE with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
	return new WebMvcConfigurerAdapter() {
		@Override
		public void addCorsMappings(CorsRegistry registry) {
			// Registry your cors url
			// registry.addMapping("/user/**");
		}
	};
}
 
Example #24
Source File: CORSConfiguration.java    From EasyEE with MIT License 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
	return new WebMvcConfigurerAdapter() {
		@Override
		public void addCorsMappings(CorsRegistry registry) {
			// Registry your cors url
			// registry.addMapping("/user/**");
		}
	};
}
 
Example #25
Source File: DispatcherServletChannelInitializer.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
public DispatcherServletChannelInitializer(Class<? extends WebMvcConfigurerAdapter> clasConfig) throws ServletException {
	MockServletContext servletContext = new MockServletContext();
	MockServletConfig servletConfig = new MockServletConfig(servletContext);

	//the alternative for web.xml
	AnnotationConfigWebApplicationContext wac = new AnnotationConfigWebApplicationContext();
	wac.setServletContext(servletContext);
	wac.setServletConfig(servletConfig);
	wac.register(clasConfig);
	wac.refresh();

	this.dispatcherServlet = new DispatcherServlet(wac);
	this.dispatcherServlet.init(servletConfig);
}
 
Example #26
Source File: TraceeSpringMvcConfiguration.java    From tracee with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean(name = TRACEE_WEBMVCCONFIGURERADAPTER_INTERNAL)
WebMvcConfigurerAdapter traceSpringMvcWebMvcConfigurerAdapter(final TraceeInterceptor traceeInterceptor) {
	return new WebMvcConfigurerAdapter() {
		@Override
		public void addInterceptors(InterceptorRegistry registry) {
			registry.addInterceptor(traceeInterceptor);
		}
	};
}
 
Example #27
Source File: CorsConfig.java    From balance-transfer-java with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer mvcConfigurer() {
	return new WebMvcConfigurerAdapter() {
		public void addCorsMappings(CorsRegistry registry) {
			registry.addMapping("/**").allowedMethods("GET", "PUT", "POST", "GET", "OPTIONS");
		}
	};
}
 
Example #28
Source File: Ap.java    From arcusipcd with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/v1/network").allowedMethods("PUT, OPTIONS");
        }
    };
}
 
Example #29
Source File: WebSocketConfig.java    From stateful-functions with Apache License 2.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfigurer() {
  return new WebMvcConfigurerAdapter() {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
      registry.addMapping("/**").allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH");
    }
  };
}
 
Example #30
Source File: CorsConfig.java    From CourseSchedulingSystem with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public WebMvcConfigurer corsConfiger(){
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("*")
                    .allowedHeaders("*")
                    .allowCredentials(true);
            super.addCorsMappings(registry);
        }
    };
}