Skip to content

Instantly share code, notes, and snippets.

@tototoshi
Created June 30, 2012 09:11
Show Gist options
  • Save tototoshi/3023056 to your computer and use it in GitHub Desktop.
Save tototoshi/3023056 to your computer and use it in GitHub Desktop.
Scala + SpringFramework
libraryDependencies ++= Seq(
"org.springframework" % "spring-context" % "3.1.1.RELEASE",
"cglib" % "cglib" % "2.2.2"
)
package com.github.tototoshi.sample
import scala.collection.JavaConversions._
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.AnnotationConfigApplicationContext
@Configuration
class AppConfig {
@Bean
def greeting(): Greeting = new GoodBye
}
trait Greeting {
def greet(): Unit
}
class Hello extends Greeting {
def greet(): Unit = println("Hello!")
}
class GoodBye extends Greeting {
def greet(): Unit = println("GoodBye!")
}
object Main extends App {
val context = new AnnotationConfigApplicationContext(classOf[AppConfig])
val greeting = context.getBean("greeting", classOf[Greeting])
greeting.greet()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment