Created
November 18, 2012 03:22
-
-
Save benhardy/4103296 to your computer and use it in GitHub Desktop.
Spring/Scala web config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration("springConf") | |
| @EnableWebMvc | |
| @ComponentScan(Array("skellybones")) | |
| @PropertySource(Array("classpath:/app.properties", "${runtime.properties.file}")) | |
| class WebConfig { | |
| @Autowired | |
| var environment: Environment = null | |
| /** | |
| * this needs to be initialized before anything else, so we make it load from | |
| * companion class. | |
| */ | |
| @Bean | |
| val props = WebConfig.props | |
| @Value("#{environment['root.url'] ?: 'http://localhost:8080'}") | |
| @BeanProperty | |
| var rootUrl: String = "" | |
| @Value("#{environment['maven.project.artifactId']}") | |
| @BeanProperty | |
| var projectArtifactId: String = "" | |
| @Value("#{environment['maven.project.groupId']}") | |
| @BeanProperty | |
| var projectGroupId: String = "" | |
| @Value("#{environment['maven.project.version']}") | |
| @BeanProperty | |
| var projectVersion: String = "" | |
| @Bean | |
| def viewResolver = { | |
| val resolver = new InternalResourceViewResolver() | |
| resolver setPrefix "/WEB-INF/jsp/" | |
| resolver setSuffix ".jsp" | |
| resolver setExposedContextBeanNames Array("springConf") | |
| resolver | |
| } | |
| } | |
| object WebConfig { | |
| /** | |
| * this needs to be static to get initialized before anything else. | |
| */ | |
| @Bean | |
| def props = { | |
| new PropertySourcesPlaceholderConfigurer() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment