Java Examples for org.springframework.web.servlet.config.annotation.WebMvcConfigurer

The following java examples will help you to understand the usage of org.springframework.web.servlet.config.annotation.WebMvcConfigurer. These source code samples are taken from different open source projects.

Example 1
Project: spring-xd-master  File: RestConfiguration.java View source code
@Bean
public WebMvcConfigurer configurer() {
    return new WebMvcConfigurerAdapter() {

        @Value("${xd.ui.allow_origin:http://localhost:9889}")
        private String allowedOrigin;

        @Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
            RestTemplateMessageConverterUtil.installMessageConverters(converters);
            for (HttpMessageConverter<?> httpMessageConverter : converters) {
                if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) {
                    final MappingJackson2HttpMessageConverter converter = (MappingJackson2HttpMessageConverter) httpMessageConverter;
                    final ObjectMapper objectMapper = converter.getObjectMapper();
                    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
                    objectMapper.setDateFormat(new ISO8601DateFormatWithMilliSeconds());
                    objectMapper.addMixInAnnotations(StepExecution.class, StepExecutionJacksonMixIn.class);
                    objectMapper.addMixInAnnotations(ExecutionContext.class, ExecutionContextJacksonMixIn.class);
                }
            }
            converters.add(new ResourceHttpMessageConverter());
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new AccessControlInterceptor(allowedOrigin));
            registry.addInterceptor(webContentInterceptor());
        }
    };
}
Example 2
Project: spring-boot-master  File: WebMvcAutoConfigurationTests.java View source code
@Test
public void validatorWithConfigurerTakesPrecedence() {
    load(MvcValidator.class);
    assertThat(this.context.getBeansOfType(ValidatorFactory.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).hasSize(1);
    String[] springValidatorBeans = this.context.getBeanNamesForType(Validator.class);
    assertThat(springValidatorBeans).containsExactly("defaultValidator", "mvcValidator");
    assertThat(this.context.getBean("mvcValidator")).isSameAs(this.context.getBean(MvcValidator.class).validator);
    // Primary Spring validator is the auto-configured one as the MVC one has been
    // customized via a WebMvcConfigurer
    assertThat(this.context.getBean(Validator.class)).isEqualTo(this.context.getBean("defaultValidator"));
}
Example 3
Project: mbit-cloud-platform-master  File: RestConfiguration.java View source code
@Bean
public WebMvcConfigurer configurer() {
    return new WebMvcConfigurerAdapter() {

        // N.B. must end in "/"
        //@Value("classpath:${xd.ui.home:file:${XD_HOME}/spring-xd-ui/dist/}")
        @Value("classpath:/static/}")
        private String resourceRoot;

        @Value("${xd.ui.allow_origin:http://localhost:9889}")
        private String allowedOrigin;

        @Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
            RestTemplateMessageConverterUtil.installMessageConverters(converters);
            for (HttpMessageConverter<?> httpMessageConverter : converters) {
                if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) {
                    final MappingJackson2HttpMessageConverter converter = (MappingJackson2HttpMessageConverter) httpMessageConverter;
                    final ObjectMapper objectMapper = converter.getObjectMapper();
                    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
                    objectMapper.setDateFormat(new ISO8601DateFormatWithMilliSeconds());
                //						objectMapper.addMixInAnnotations(StepExecution.class, StepExecutionJacksonMixIn.class);
                //						objectMapper.addMixInAnnotations(ExecutionContext.class, ExecutionContextJacksonMixIn.class);
                }
            }
            converters.add(new ResourceHttpMessageConverter());
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new AccessControlInterceptor(allowedOrigin));
        }

        // add a static resource handler for the UI
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/" + ConfigLocations.XD_ADMIN_UI_BASE_PATH + "/**", "/" + ConfigLocations.XD_ADMIN_UI_BASE_PATH + "/").addResourceLocations(resourceRoot);
        }

        @Override
        public void addViewControllers(ViewControllerRegistry registry) {
            registry.addViewController(ConfigLocations.XD_ADMIN_UI_BASE_PATH).setViewName("redirect:/" + ConfigLocations.XD_ADMIN_UI_BASE_PATH + "/");
            registry.addViewController(ConfigLocations.XD_ADMIN_UI_BASE_PATH + "/").setViewName("index.html");
        }
    };
}
Example 4
Project: school-master  File: Security.java View source code
@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurerAdapter() {

        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE");
        }
    };
}
Example 5
Project: spring-cloud-dataflow-master  File: WebConfiguration.java View source code
@Bean
public WebMvcConfigurer configurer() {
    return new WebMvcConfigurerAdapter() {

        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            configurer.setUseSuffixPatternMatch(false);
        }
    };
}