我正在SCALA中编写 Spring 应用程序。我不得不改变
class Application {}
至object Application {}
使生成的main()
静态。
@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration
@EnableConfigurationProperties
@Import(Array(classOf[CoreConfiguration]))
object Application extends App {
override def main(args: Array[String]): Unit = {
val appCtx = SpringApplication.run(classOf[Application], args: _*)
}
}
导致SPRING抱怨最终类(最终类应用程序):
BeanDefinitionParsingException: Configuration problem: @Configuration class 'Application' may not be final. Remove the final modifier to continue.
如何在SCALA中创建Spring Application类?
答案 0 :(得分:1)
在同一文件中创建随播广告对象,即同伴的应用对象。结果类似于:
@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration
@EnableConfigurationProperties
@Import(Array(classOf[CoreConfiguration]))
class Application {
def run(args: Array[String]): Unit = {
val appCtx = SpringApplication.run(classOf[Application], args: _*)
}
}
object Application extends App {
override def main(args: Array[String]): Unit = {
new Application().run(args)
}
}