package com.guanglian.question.config;

import java.io.IOException;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.*;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.web.accept.ContentNegotiationManagerFactoryBean;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ImportResource({"classpath*:spring/spring-web.xml","classpath*:spring/spring-service.xml","classpath*:spring/spring-dao.xml"})
@ComponentScan("com.guanglian.question.controller")
public class WebConfig extends WebMvcConfigurerAdapter {

	@Bean
	public ViewResolver getInternalResourceViewResolver() {
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		resolver.setPrefix("/WEB-INF/views/");
		resolver.setSuffix(".jsp");
		return resolver;
	}

	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// TODO Auto-generated method stub
		super.addResourceHandlers(registry);
	}

//	  @Bean
//	  public MessageSource messageSource() {
//	    ReloadableResourceBundleMessageSource messageSource =
//	        new ReloadableResourceBundleMessageSource();
//	    messageSource.setBasename("file:///Users/habuma/messages");
//	    messageSource.setCacheSeconds(10);
//	    return messageSource;
//	  }

	@Bean
	public MultipartResolver multipartResolver() throws IOException {
		CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
		multipartResolver.setMaxInMemorySize(2097152);
		multipartResolver.setMaxUploadSize(2097152*10);
		return multipartResolver;
	}

}
