Fight the Future

Java言語とJVM、そしてJavaエコシステム全般にまつわること

ScalaのSpring MVCコントローラに@AutowiredでInjectする

これの続き。 jyukutyo.hatenablog.com

素直に@Autowiredアノテーションつけるだけでできた。

package hoge

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping

@Controller
class HogeController {

  @Autowired
  implicit var context: ApplicationContext = _

  @RequestMapping(Array("/hoge"))
  def hoge(): String = {
    println(context.getBeanDefinitionNames)
    "/hoge.vm"
  }
}