有没有人有用Scala在play应用程序中引导Spring Boot的示例代码?
发布于 2016-01-07 04:22:05
至于第一个,我不确定是否真的有必要编写“特殊代码”来混合Boot和Play。Boot是一个自动配置和服务器部署工具,是Spring框架的一部分。
Scala在JVM上运行,并针对JVM进行编译。得到的字节码在所有情况下都是几乎相同的。因此,只要像编写java一样编写代码即可。您甚至可以使用gradle或Maven。对于资源来说,这个blog是一个很好的开始。
现在,是自动装配的时候了。你只需要scala bean和任何必要的java转换即可。Java转换是隐式处理的,只是将scala特性构建到java对象上,虽然这并不是真正必要的,但我相信通过丰富/拉皮条我的库模式。自动装配只是一个使用正确注释的问题。但是,必须使用@BeanProperty注释来生成必要的getter和setter。
import scala.beans._
import scala.collection.JavaConversions._
import org.springframework.beans.factory.annotation.Required
import org.springframework.beans.factory.annotation.Autowired
@Component
@Autowire //if wanted
class SpringTest{
//using javax to combine Autowire potentially differently named variables
@Required
@BeanProperty
@Resource(name="varName")
var resourceVar:String = null
//using basic autowiring
@BeanProperty
@Autowire //same for instance variables as objects
var autoVar:String = null
//etc.....
}https://stackoverflow.com/questions/34296345
复制相似问题