本文整理汇总了Scala中org.springframework.context.ApplicationContext类的典型用法代码示例。如果您正苦于以下问题:Scala ApplicationContext类的具体用法?Scala ApplicationContext怎么用?Scala ApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ApplicationContext类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: AppConfiguration
//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery.extension
import akka.actor.ActorSystem
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.{Bean, Configuration}
import scala.concurrent.ExecutionContext
@Configuration
class AppConfiguration {
@Autowired
var applicationContext: ApplicationContext = _
@Bean
def actorSystem(): ActorSystem = {
val sys = ActorSystem()
SpringExtension.provider.get(sys).initialize(applicationContext)
sys
}
@Bean
def executionContext(actorSystem: ActorSystem): ExecutionContext =
actorSystem.dispatcher
}
示例2: SpringRunner
//设置package包名称以及导入依赖的类
package com.ntsdev.run
import com.ntsdev.config.{LocalGraphConfiguration, RemoteGraphConfiguration, EnvironmentConfig}
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.{AnnotationConfigApplicationContext, Configuration}
@Configuration
class SpringRunner
object SpringRunner extends App with EnvironmentConfig {
val logger = LoggerFactory.getLogger(getClass)
logger.info(s"Active Spring Profile: [$activeSpringProfile]")
if("cloud" equals activeSpringProfile) {
logger.info("Loading cloud configuration...")
val context: ApplicationContext = new AnnotationConfigApplicationContext(classOf[RemoteGraphConfiguration])
}
else {
import com.ntsdev.service.TestDataService
logger.info("Loading local configuration...")
val context: ApplicationContext = new AnnotationConfigApplicationContext(classOf[LocalGraphConfiguration])
val testDataService: TestDataService = context.getBean("testDataService").asInstanceOf[TestDataService]
testDataService.loadTestData()
}
}