Created
June 30, 2012 09:11
-
-
Save tototoshi/3023056 to your computer and use it in GitHub Desktop.
Scala + SpringFramework
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
libraryDependencies ++= Seq( | |
"org.springframework" % "spring-context" % "3.1.1.RELEASE", | |
"cglib" % "cglib" % "2.2.2" | |
) |
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
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