Skip to content

Instantly share code, notes, and snippets.

@cer
Created July 14, 2015 15:58
Show Gist options
  • Save cer/a4715375d903eaddb0b2 to your computer and use it in GitHub Desktop.
Save cer/a4715375d903eaddb0b2 to your computer and use it in GitHub Desktop.
package net.chrisrichardson.microservices.restfulspringboot
import org.springframework.cloud.netflix.eureka.EnableEurekaClient
import org.springframework.context.annotation._
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import net.chrisrichardson.microservices.restfulspringboot.backend.ScalaObjectMapper
import net.chrisrichardson.microservices.restfulspringboot.dustview.DustViewResolver
import org.springframework.web.client.{ResponseErrorHandler, RestTemplate}
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import scala.collection.JavaConversions._
import org.springframework.http.client.ClientHttpResponse
@Configuration
@EnableAutoConfiguration
@ComponentScan
@Import(Array(classOf[EurekaClientConfiguration]))
class UserRegistrationConfiguration {
@Bean
@Primary
def scalaObjectMapper() = new ScalaObjectMapper
@Bean
def dustViewResolver = {
val resolver = new DustViewResolver
resolver.setPrefix("/WEB-INF/views/")
resolver.setSuffix(".dust")
resolver
}
class DummyClass {}
@Bean
@Profile(Array("!enableEureka"))
def restTemplate() = new RestTemplate()
@Bean
def restTemplateInitializer(restTemplate : RestTemplate) : DummyClass = {
restTemplate.getMessageConverters foreach {
case mc: MappingJackson2HttpMessageConverter =>
mc.setObjectMapper(scalaObjectMapper())
case _ =>
}
new DummyClass()
}
}
@Configuration
@EnableEurekaClient
@Profile(Array("enableEureka"))
class EurekaClientConfiguration {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment