Package de.codecentric.moviedatabase.config

Source Code of de.codecentric.moviedatabase.config.ApplicationConfiguration

package de.codecentric.moviedatabase.config;

import java.nio.charset.Charset;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
@EnableWebMvc
@Import({ViewConfiguration.class, ControllerConfiguration.class})
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {
 
  // Maps resources path to webapp/resources
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
  }
 
  @Override
  public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(jsonHttpMessageConverter());
    converters.add(new StringHttpMessageConverter(Charset.forName("UTF-8")));
  }

  @Bean
  public JacksonObjectMapper jacksonObjectMapper() {
    return new JacksonObjectMapper();
  }
 
  @Bean
  public MappingJacksonHttpMessageConverter jsonHttpMessageConverter() {
    MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter();
    converter.setObjectMapper(jacksonObjectMapper());
    return converter;
  }
}
TOP

Related Classes of de.codecentric.moviedatabase.config.ApplicationConfiguration

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.