Skip to content

Instantly share code, notes, and snippets.

@benhardy
Created November 18, 2012 03:22
Show Gist options
  • Select an option

  • Save benhardy/4103296 to your computer and use it in GitHub Desktop.

Select an option

Save benhardy/4103296 to your computer and use it in GitHub Desktop.
Spring/Scala web config
@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