package net.petrikainulainen.spring.datasolr.config; import org.springframework.context.MessageSource; import org.springframework.context.annotation.*; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.data.web.PageableArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; 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.mvc.method.annotation.ServletWebArgumentResolverAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import java.util.List; /** * @author Petri Kainulainen */ @Configuration @EnableWebMvc @ComponentScan(basePackages = { "net.petrikainulainen.spring.datasolr.common", "net.petrikainulainen.spring.datasolr.todo.controller", "net.petrikainulainen.spring.datasolr.todo.service", "net.petrikainulainen.spring.datasolr.security", "net.petrikainulainen.spring.datasolr.user.controller" }) @Import({EmbeddedSolrContext.class, HttpSolrContext.class, PersistenceContext.class}) @ImportResource("classpath:exampleApplicationContext-security.xml") @PropertySource("classpath:application.properties") public class ExampleApplicationContext extends WebMvcConfigurerAdapter { private static final String MESSAGE_SOURCE_BASE_NAME = "i18n/messages"; private static final String VIEW_RESOLVER_PREFIX = "/WEB-INF/jsp/"; private static final String VIEW_RESOLVER_SUFFIX = ".jsp"; @Override public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { PageableArgumentResolver pageableArgumentResolver = new PageableArgumentResolver(); argumentResolvers.add(new ServletWebArgumentResolverAdapter(pageableArgumentResolver)); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("/static/"); } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); } @Bean public MessageSource messageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename(MESSAGE_SOURCE_BASE_NAME); messageSource.setUseCodeAsDefaultMessage(true); return messageSource; } @Bean public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { PropertySourcesPlaceholderConfigurer properties = new PropertySourcesPlaceholderConfigurer(); properties.setLocation(new ClassPathResource( "application.properties" )); properties.setIgnoreResourceNotFound(false); return properties; } @Bean public ViewResolver viewResolver() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); viewResolver.setViewClass(JstlView.class); viewResolver.setPrefix(VIEW_RESOLVER_PREFIX); viewResolver.setSuffix(VIEW_RESOLVER_SUFFIX); return viewResolver; } }