Java tutorial
/** * Copyright 2014 Remi Guillemette <rguillemette@n4dev.ca> * This work is free. You can redistribute it and/or modify it under the * terms of the Do What The Fuck You Want To Public License, Version 2, * as published by Sam Hocevar. See the COPYING file for more details. */ package ca.n4dev.dev.worktime.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; 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.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * @author rguillemette * @since Sep 30, 2014 */ @Configuration @ComponentScan(basePackages = "ca.n4dev.dev.worktime") @EnableWebMvc @Import({ SpringHibernateJPAConfig.class, ThymeleafMvcConfig.class, SecurityConfig.class }) @PropertySource("classpath:worktime.properties") public class ApplicationConfig extends WebMvcConfigurerAdapter { // Maps resources path to webapp/resources @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); } // Only needed if we are using @Value and ${...} when referencing properties @Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer propertySources = new PropertySourcesPlaceholderConfigurer(); Resource[] resources = new ClassPathResource[] { new ClassPathResource("worktime.properties") }; propertySources.setLocations(resources); propertySources.setIgnoreUnresolvablePlaceholders(true); return propertySources; } // Provides internationalization of messages @Bean public ResourceBundleMessageSource messageSource() { ResourceBundleMessageSource source = new ResourceBundleMessageSource(); source.setBasename("messages"); return source; } }