本文整理汇总了Scala中play.api.Application类的典型用法代码示例。如果您正苦于以下问题:Scala Application类的具体用法?Scala Application怎么用?Scala Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Application类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: myPublicAddress
//设置package包名称以及导入依赖的类
package org.zalando.hutmann.spec
import org.scalatest.concurrent.PatienceConfiguration.Interval
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Seconds, Span }
import org.scalatestplus.play.{ PlaySpec, PortNumber, WsScalaTestClient }
import play.api.Application
import play.api.http.{ HeaderNames, MimeTypes }
import play.api.libs.ws.{ WSClient, WSResponse }
trait PlayUnitSpec extends PlaySpec with ScalaFutures with WsScalaTestClient {
def myPublicAddress(): String
implicit val portNumber: PortNumber
def callWs(testPaymentGatewayURL: String)(implicit app: Application): WSResponse = {
implicit val wSClient = app.injector.instanceOf[WSClient]
val callbackURL = s"http://${myPublicAddress()}/callback"
whenReady(
wsUrl(testPaymentGatewayURL)
.withQueryStringParameters("callbackURL" -> callbackURL)
.withHttpHeaders(HeaderNames.ACCEPT -> MimeTypes.TEXT)
.get(),
Interval(Span(10, Seconds))
) { result =>
result
}
}
}
开发者ID:zalando-incubator,项目名称:hutmann,代码行数:29,代码来源:PlayUnitSpec.scala
示例2: injectorModules
//设置package包名称以及导入依赖的类
package global
import actors.ChadashSystem
import com.google.inject.{Guice, Module}
import play.api.mvc.{EssentialAction, Filters}
import play.api.{Application, GlobalSettings, Logger, Mode}
import play.filters.gzip.GzipFilter
import play.filters.headers.SecurityHeadersFilter
trait AppGlobalSettings extends GlobalSettings {
private var INJECTOR: Option[com.google.inject.Injector] = None
def injectorModules(): Seq[Module]
override def onStart(app: Application) {
INJECTOR = Some(Guice.createInjector(injectorModules(): _*))
}
override def onStop(app: Application) {
Logger.info("Application shutdown...")
if(app.mode != Mode.Test)
ChadashSystem.system.shutdown()
}
override def doFilter(next: EssentialAction): EssentialAction = {
Filters(super.doFilter(next), new GzipFilter(), SecurityHeadersFilter())
}
override def getControllerInstance[A](controllerClass: Class[A]): A = {
INJECTOR match {
case Some(x) => x.getInstance(controllerClass)
case None => throw new UnsupportedOperationException("The DI framework has not been setup yet!")
}
}
}
开发者ID:lifeway,项目名称:Chadash,代码行数:37,代码来源:AppGlobalSettings.scala
示例3: PlayWithFoodWithTestComponents
//设置package包名称以及导入依赖的类
package testhelpers
import config.ExampleComponents
import org.scalatest.BeforeAndAfterEach
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.components.OneServerPerTestWithComponents
import play.api.db.evolutions.Evolutions
import play.api.http.Status
import play.api.libs.ws.WSClient
import play.api.test.{DefaultAwaitTimeout, FutureAwaits, Helpers, TestServer}
import play.api.{Application, Configuration}
import slick.dbio.DBIO
trait PlayWithFoodWithServerBaseTest extends PlaySpec
with OneServerPerTestWithComponents
with DefaultFutureDuration
with DefaultExecutionContext
with Status
with DefaultAwaitTimeout
with FutureAwaits
with BeforeAndAfterEach {
class PlayWithFoodWithTestComponents extends ExampleComponents(context) {
override def configuration: Configuration = {
val testConfig = Configuration.from(TestUtils.config)
val config = super.configuration
val testConfigMerged = config ++ testConfig
config.toString
testConfigMerged
}
implicit lazy val testWsClient: WSClient = wsClient
}
override def components: PlayWithFoodWithTestComponents = new PlayWithFoodWithTestComponents
private def runServerAndCleanUpInMemDb(c: PlayWithFoodWithTestComponents) = {
runServerAndExecute(c.application) {
val dbapi = c.dbApi
Evolutions.cleanupEvolutions(dbapi.database("default"))
}
}
override protected def afterEach(): Unit = {
runServerAndCleanUpInMemDb(components)
}
protected def runServerAndExecute[T](app: Application)(blockWithComponents: => T): T = {
Helpers.running(TestServer(port, app))(blockWithComponents)
}
def runAndAwaitResult[T](action: DBIO[T])(implicit components: ExampleComponents): T = {
TestUtils.runAndAwaitResult(action)(components.actionRunner, duration)
}
}
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:58,代码来源:PlayWithFoodWithServerBaseTest.scala
示例4: app
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentrelationships.support
import com.codahale.metrics.MetricRegistry
import com.kenshoo.play.metrics.Metrics
import org.scalatest.{Matchers, Suite}
import play.api.Application
import scala.collection.JavaConversions
trait MetricTestSupport {
self: Suite with Matchers =>
def app: Application
private var metricsRegistry: MetricRegistry = _
def givenCleanMetricRegistry(): Unit = {
val registry = app.injector.instanceOf[Metrics].defaultRegistry
for (metric <- JavaConversions.asScalaIterator[String](registry.getMetrics.keySet().iterator())) {
registry.remove(metric)
}
metricsRegistry = registry
}
def timerShouldExistsAndBeenUpdated(metric: String): Unit = {
metricsRegistry.getTimers.get(s"Timer-$metric").getCount should be >= 1L
}
}
开发者ID:hmrc,项目名称:agent-client-relationships,代码行数:30,代码来源:MetricTestSupport.scala
示例5: Global
//设置package包名称以及导入依赖的类
import org.squeryl.adapters.{H2Adapter, MySQLAdapter, PostgreSqlAdapter}
import org.squeryl.internals.DatabaseAdapter
import org.squeryl.{Session, SessionFactory}
import play.api.db.DB
import play.api.{Application, GlobalSettings}
object Global extends GlobalSettings {
override def onStart(app: Application) {
SessionFactory.concreteFactory = app.configuration.getString("db.default.driver") match {
case Some("org.h2.Driver") => Some(() => getSession(new H2Adapter, app))
case Some("org.postgresql.Driver") => Some(() => getSession(new PostgreSqlAdapter, app))
case Some("com.mysql.jdbc.Driver") => Some(() => getSession(new MySQLAdapter, app))
case _ => sys.error("Database driver must be either org.h2.Driver or org.postgresql.Driver")
}
}
def getSession(adapter:DatabaseAdapter, app: Application) = Session.create(DB.getConnection()(app), adapter)
}
开发者ID:chang850,项目名称:squeryl,代码行数:21,代码来源:Global.scala
示例6: PlayGlobalSettings
//设置package包名称以及导入依赖的类
package utils
import java.util.TimeZone
import jdub.async.Database
import org.joda.time.DateTimeZone
import play.api.{ Application, GlobalSettings }
import services.database.Schema
object PlayGlobalSettings extends GlobalSettings {
override def onStart(app: Application) = {
DateTimeZone.setDefault(DateTimeZone.UTC)
TimeZone.setDefault(TimeZone.getTimeZone("UTC"))
val cnf = play.api.Play.current.configuration
val host = cnf.getString("db.host").getOrElse("localhost")
val port = 5432
val database = cnf.getString("db.database")
val username = cnf.getString("db.username").getOrElse("silhouette")
val password = cnf.getString("db.password")
Database.open(username, host, port, password, database)
Schema.update()
super.onStart(app)
}
override def onStop(app: Application) = {
Database.close()
super.onStop(app)
}
}
开发者ID:laurinka,项目名称:golfmit,代码行数:33,代码来源:PlayGlobalSettings.scala
示例7: CmdTask
//设置package包名称以及导入依赖的类
package com.galacticfog.lambda.scheduler
import java.util.UUID
import org.apache.mesos.{Protos, MesosSchedulerDriver}
import org.apache.mesos.Protos.FrameworkInfo
import play.api.{Logger, Play, Application, GlobalSettings}
import scala.collection.mutable
import scala.concurrent.Future
import scala.sys.SystemProperties
import scala.concurrent.duration._
import Play.current
import play.api.libs.concurrent.Execution.Implicits._
import scala.util.Try
case class CmdTask(uuid: UUID, handlerMethod: String, jarUrl: String)
object Global extends GlobalSettings {
lazy val driver: Try[MesosSchedulerDriver] = Try {
Logger.info("creating LambdaScheduler")
val scheduler = new LambdaScheduler
val master = current.configuration.getString("master") getOrElse "localhost:5050"
Logger.info(s"registering with mesos-master: ${master}")
val schedulerHostname = current.configuration.getString("hostname") getOrElse java.net.InetAddress.getLocalHost.getHostName
Logger.info(s"scheduler on: ${schedulerHostname}")
val frameworkInfoBuilder = FrameworkInfo.newBuilder()
.setName("gestalt-lambda-scheduler")
.setFailoverTimeout(60.seconds.toMillis)
.setUser("")
.setCheckpoint(true)
.setHostname(schedulerHostname)
val frameworkInfo = frameworkInfoBuilder.build()
Logger.info(s"scheduler on: ${schedulerHostname}")
val implicitAcknowledgements = false
new MesosSchedulerDriver( scheduler, frameworkInfo, master, implicitAcknowledgements )
}
val taskQueue = new mutable.Queue[CmdTask]
override def onStart(app: Application): Unit = {
Logger.info("onStart")
driver foreach { d =>
Logger.info("starting driver")
Future { d.run } map println
}
}
override def onStop(app: Application): Unit = {
Logger.info("onStop")
driver foreach {
Logger.info("stopping driver")
_.stop()
}
}
}
开发者ID:GalacticFog,项目名称:gestalt-lambda,代码行数:62,代码来源:Global.scala
示例8: AwardsRepoSpec
//设置package包名称以及导入依赖的类
package repo
import models.AwardsRepo
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.Application
import play.api.test.WithApplication
import scala.concurrent.Await
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class AwardsRepoSpec extends Specification {
sequential
def awardsRepo(implicit app: Application) = Application.instanceCache[AwardsRepo].apply(app)
"Awards repository" should {
"get a record" in new WithApplication {
val result = awardsRepo.getAll
val response = Await.result(result, Duration.Inf)
response.head.name === "microsoft"
}
"delete a record" in new WithApplication {
val result = awardsRepo.delete(2)
val response = Await.result(result, Duration.Inf)
response === 1
}
"add a record" in new WithApplication {
val result = awardsRepo.add("scjp", "good", "2015", 1)
val response = Await.result(result, Duration.Inf)
response === 1
}
"UPDATE a record" in new WithApplication {
val result = awardsRepo.update(2, "NCR Certificate", "worst", "2016", 3)
val response = Await.result(result, Duration.Inf)
response === 1
}
"get a record by id" in new WithApplication {
val result = awardsRepo.getById(2)
val response = Await.result(result, Duration.Inf)
response.get.name === "sun certificate"
}
"get a record by User id" in new WithApplication {
val result = awardsRepo.getByUserId(1)
val response = Await.result(result, Duration.Inf)
response.head.name === "microsoft"
}
}
}
开发者ID:aarwee,项目名称:PLAY-SLICK-DEEPTI-KUNAL-RISHABH,代码行数:56,代码来源:AwardsRepoSpec.scala
示例9: AssignmentRepoSpec
//设置package包名称以及导入依赖的类
package repo
import models.AssignmentRepo
import org.specs2.mutable.Specification
import play.api.Application
import play.api.test.WithApplication
import scala.concurrent.Await
import scala.concurrent.duration.Duration
class AssignmentRepoSpec extends Specification {
sequential
def assignmentRepo(implicit app: Application) = Application.instanceCache[AssignmentRepo].apply(app)
"Awards repository" should {
"get a record" in new WithApplication {
val result = assignmentRepo.getAll
val response = Await.result(result, Duration.Inf)
response.head.name === "c++"
}
"delete a record" in new WithApplication {
val result = assignmentRepo.delete(1)
val response = Await.result(result, Duration.Inf)
response === 1
}
"add a record" in new WithApplication {
val result = assignmentRepo.add("scala", "2015-08-08", 22, "good",3)
val response = Await.result(result, Duration.Inf)
response === 1
}
"UPDATE a record" in new WithApplication {
val result = assignmentRepo.update(1, "scala", "2015-08-08", 22, "good", 1)
val response = Await.result(result, Duration.Inf)
}
"get record by id" in new WithApplication{
val result = assignmentRepo.getById(1)
val response = Await.result(result, Duration.Inf)
response.get.name === "c++"
}
"get record by id" in new WithApplication{
val result = assignmentRepo.getByUserId(1)
val response = Await.result(result, Duration.Inf)
response.head.name === "c++"
}
}
}
开发者ID:aarwee,项目名称:PLAY-SLICK-DEEPTI-KUNAL-RISHABH,代码行数:53,代码来源:AssignmentRepoSpec.scala
示例10: AwardRepoTest
//设置package包名称以及导入依赖的类
package repository
import models.Award
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.Application
import play.api.test.WithApplication
import scala.concurrent.Await
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class AwardRepoTest extends Specification{
def awardRepo(implicit app:Application)=Application.instanceCache[AwardRepo].apply(app)
"Award Repository" should {
"get award records" in new WithApplication {
val res = awardRepo.getAll()
val response = Await.result(res, Duration.Inf)
response.head.id ===1
}
"insert award records" in new WithApplication() {
val res=awardRepo.insert(4,"best orator","school level")
val response=Await.result(res,Duration.Inf)
response===1
}
"update award records" in new WithApplication{
val res=awardRepo.update(1,"best singer","school level")
val response=Await.result(res,Duration.Inf)
response===0
}
"delete award records" in new WithApplication() {
val res=awardRepo.delete("best dancer")
val response=Await.result(res,Duration.Inf)
response===0
}
"get awards by id" in new WithApplication() {
val res=awardRepo.getAward(1)
val response=Await.result(res,Duration.Inf)
response===Vector(Award(1,"best programmer","school level"))
}
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:50,代码来源:AwardRepoTest.scala
示例11: LanguageRepoTest
//设置package包名称以及导入依赖的类
package repository
import models.Language
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.Application
import play.api.test.WithApplication
import scala.concurrent.Await
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class LanguageRepoTest extends Specification{
def langRepo(implicit app:Application)=Application.instanceCache[LanguageRepo].apply(app)
"Language Repository" should {
"get language records" in new WithApplication {
val res = langRepo.getAll()
val response = Await.result(res, Duration.Inf)
response.head.id ===1
}
"insert language records" in new WithApplication() {
val res=langRepo.insert(1,"french","basic")
val response=Await.result(res,Duration.Inf)
response===1
}
"update language records" in new WithApplication(){
val res=langRepo.update(1,"spansih","basic")
val response=Await.result(res,Duration.Inf)
response === 1
}
"delete language record" in new WithApplication() {
val res=langRepo.delete("hindi")
val response=Await.result(res,Duration.Inf)
response===1
}
"get records by id" in new WithApplication() {
val res=langRepo.getLanguage(1)
val response=Await.result(res,Duration.Inf)
response===Vector(Language(1,"hindi","advanced"))
}
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:54,代码来源:LanguageRepoTest.scala
示例12: UserRepoTest
//设置package包名称以及导入依赖的类
package repository
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.Application
import play.api.test.WithApplication
import scala.concurrent.Await
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class UserRepoTest extends Specification {
def userRepo(implicit app:Application)=Application.instanceCache[UserRepo].apply(app)
"User Repository" should {
"get a student record" in new WithApplication {
val res=userRepo.getUser("[email protected]")
val response=Await.result(res,Duration.Inf)
response.head.name === "himani"
}
"get all student records" in new WithApplication() {
val res=userRepo.getAll()
val response=Await.result(res,Duration.Inf)
response.head.name==="himani"
}
"add student records" in new WithApplication{
val res=userRepo.insert(3,"santosh","[email protected]","72745690","santosh")
val response=Await.result(res,Duration.Inf)
response ===1
}
"delete student record" in new WithApplication{
val res=userRepo.delete(2)
val response=Await.result(res,Duration.Inf)
response ===1
}
"update student record" in new WithApplication() {
val res=userRepo.update(1,"simar","[email protected]","22469870","simar")
val response=Await.result(res,Duration.Inf)
response===1
}
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:49,代码来源:UserRepoTest.scala
示例13: AssignmentRepoTest
//设置package包名称以及导入依赖的类
package repository
import models.Assignment
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.Application
import play.api.test.WithApplication
import scala.concurrent.Await
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class AssignmentRepoTest extends Specification{
def assigRepo(implicit app:Application)=Application.instanceCache[AssignmentRepo].apply(app)
"Assignment Repository" should {
"get assignment records" in new WithApplication {
val res = assigRepo.getAll()
val response = Await.result(res, Duration.Inf)
response.head.id ===1
}
"insert assignment records" in new WithApplication() {
val res=assigRepo.insert(1,"slick",5,"no remark")
val response=Await.result(res,Duration.Inf)
response===1
}
"delete assignment record" in new WithApplication() {
val res=assigRepo.delete(1)
val response=Await.result(res,Duration.Inf)
response===1
}
"update assignment records" in new WithApplication(){
val res=assigRepo.update(1,"c++",7,"can do better")
val response=Await.result(res,Duration.Inf)
response === 1
}
"get assignment by id" in new WithApplication() {
val res=assigRepo.getAssignment(1)
val response=Await.result(res,Duration.Inf)
response===Vector(Assignment(1,"scala",7,"no remark"))
}
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:53,代码来源:AssignmentRepoTest.scala
示例14: ProgLanguageRepoTest
//设置package包名称以及导入依赖的类
package repository
import models.ProgLanguage
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.Application
import play.api.test.WithApplication
import scala.concurrent.Await
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class ProgLanguageRepoTest extends Specification{
def plangRepo(implicit app:Application)=Application.instanceCache[ProgLanguageRepo].apply(app)
"Programming language Repository" should {
"get programming language records" in new WithApplication {
val res = plangRepo.getAll()
val response = Await.result(res, Duration.Inf)
response.head.id ===1
}
"insert programming language records" in new WithApplication() {
val res=plangRepo.insert(4,"c#")
val response=Await.result(res,Duration.Inf)
response===1
}
"update programming language records" in new WithApplication(){
val res=plangRepo.update(1,"java")
val response=Await.result(res,Duration.Inf)
response === 1
}
"delete programming language record" in new WithApplication() {
val res=plangRepo.delete("c++")
val response=Await.result(res,Duration.Inf)
response===1
}
"get a particular record" in new WithApplication{
val res=plangRepo.getProgLanguage(1)
val response=Await.result(res,Duration.Inf)
response===Vector(ProgLanguage(1,"c++"))
}
}
}
开发者ID:PallaviSingh1992,项目名称:Play-Slick-Assig2-v2,代码行数:55,代码来源:ProgLanguageRepoTest.scala
示例15: FrontendGlobal
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.trustregistration
import java.io.File
import com.typesafe.config.Config
import net.ceedubs.ficus.Ficus._
import play.api.Mode._
import play.api.mvc.Request
import play.api.{Application, Configuration, Play}
import play.twirl.api.Html
import uk.gov.hmrc.crypto.ApplicationCrypto
import uk.gov.hmrc.play.audit.filters.FrontendAuditFilter
import uk.gov.hmrc.play.config.{AppName, ControllerConfig, RunMode}
import uk.gov.hmrc.play.frontend.bootstrap.DefaultFrontendGlobal
import uk.gov.hmrc.play.http.logging.filters.FrontendLoggingFilter
object FrontendGlobal
extends DefaultFrontendGlobal {
override val auditConnector = FrontendAuditConnector
override val loggingFilter = LoggingFilter
override val frontendAuditFilter = AuditFilter
override def onStart(app: Application) {
super.onStart(app)
ApplicationCrypto.verifyConfiguration()
}
override def onLoadConfig(config: Configuration, path: File, classloader: ClassLoader, mode: Mode): Configuration = {
super.onLoadConfig(config, path, classloader, mode)
}
override def standardErrorTemplate(pageTitle: String, heading: String, message: String)(implicit rh: Request[_]): Html =
uk.gov.hmrc.trustregistration.views.html.error_template(pageTitle, heading, message)
override def microserviceMetricsConfig(implicit app: Application): Option[Configuration] = app.configuration.getConfig(s"microservice.metrics")
}
object ControllerConfiguration extends ControllerConfig {
lazy val controllerConfigs = Play.current.configuration.underlying.as[Config]("controllers")
}
object LoggingFilter extends FrontendLoggingFilter {
override def controllerNeedsLogging(controllerName: String) = ControllerConfiguration.paramsForController(controllerName).needsLogging
}
object AuditFilter extends FrontendAuditFilter with RunMode with AppName {
override lazy val maskedFormFields = Seq("password")
override lazy val applicationPort = None
override lazy val auditConnector = FrontendAuditConnector
override def controllerNeedsAuditing(controllerName: String) = ControllerConfiguration.paramsForController(controllerName).needsAuditing
}
开发者ID:hmrc,项目名称:trust-registration-frontend,代码行数:58,代码来源:frontendGlobal.scala
示例16: HomeControllerSpec
//设置package包名称以及导入依赖的类
package controllers
import models.UsersRepository
import org.specs2.execute.{AsResult, Result}
import org.specs2.mutable.Around
import org.specs2.specification.Scope
import play.api.Application
import play.api.mvc._
import play.api.test.{FakeRequest, PlaySpecification}
class HomeControllerSpec extends PlaySpecification with Results {
abstract class WithTestApplication extends Around with Scope with TestEnvironment {
lazy val app: Application = fakeApp
lazy val controller = new HomeController(knolxControllerComponent)
override def around[T: AsResult](t: => T): Result = {
TestHelpers.running(app)(AsResult.effectively(t))
}
}
"HomeController" should {
"redirect index page to sessions page" in new WithTestApplication {
val result = controller.index(FakeRequest())
status(result) must be equalTo SEE_OTHER
}
}
}
开发者ID:knoldus,项目名称:knolx-portal,代码行数:33,代码来源:HomeControllerSpec.scala
示例17: MyApplicationLoader
//设置package包名称以及导入依赖的类
package my.samples.core
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.{ LazyLogging, StrictLogging }
import controllers.Assets
import play.api.{ Application, BuiltInComponentsFromContext, Configuration, _ }
import play.api.libs.ws.ahc.AhcWSComponents
import my.samples.controllers.MyApplicationController
import play.api.ApplicationLoader.Context
import play.api.routing.Router
import router.Routes
import scala.concurrent.Future
// compile time DI for loading the play application
final class MyApplicationLoader extends ApplicationLoader with LazyLogging {
override def load(context: Context): Application = {
val configuration = Configuration(ConfigFactory.load())
val newContext = context.copy(initialConfiguration = configuration)
LoggerConfigurator(newContext.environment.classLoader)
.foreach(_.configure(newContext.environment))
new MyApp(newContext).application
}
}
class MyApp(context: Context)
extends BuiltInComponentsFromContext(context) with AhcWSComponents with StrictLogging {
implicit val s = monix.execution.Scheduler.Implicits.global
def stop(bindings: AppBindings) = {
logger.info("stopping application")
bindings.globalChannel.publishChannel.onComplete()
}
def start = {
logger.info("starting application")
AppBindings(actorSystem, materializer)
}
// 1. create the dependencies that will be injected
lazy val appBindings = start
// 2. inject the dependencies into the controllers
lazy val applicationController = new MyApplicationController(appBindings)
lazy val assets = new Assets(httpErrorHandler)
override def router: Router = new Routes(
httpErrorHandler, applicationController, assets
)
// 3. add the shutdown hook to properly dispose all connections
applicationLifecycle.addStopHook { () => Future(stop(appBindings)) }
}
开发者ID:joesan,项目名称:monix-samples,代码行数:55,代码来源:MyApplicationLoader.scala
示例18: overrideModules
//设置package包名称以及导入依赖的类
package com.eigenroute.scalikejdbctesthelpers
import org.scalatest._
import play.api.Application
import play.api.inject.guice.{GuiceApplicationBuilder, GuiceableModule}
import play.api.test._
trait OneAppPerTestWithOverrides extends SuiteMixin { this: Suite ?
def overrideModules: Seq[GuiceableModule] = Nil
def newAppForTest(testData: TestData): Application =
new GuiceApplicationBuilder()
.overrides(overrideModules: _*)
.build
var appPerTest: Application = _
implicit final def app: Application = synchronized { appPerTest }
abstract override def withFixture(test: NoArgTest) = {
synchronized { appPerTest = newAppForTest(test) }
Helpers.running(app) { super.withFixture(test) }
}
}
开发者ID:shafiquejamal,项目名称:eigenroute-scalikejdbc-test-helpers,代码行数:26,代码来源:OneAppPerTestWithOverrides.scala
示例19: Restaurante
//设置package包名称以及导入依赖的类
package models
import javax.inject._
import play.api.Application
import slick.driver.JdbcProfile
import slick.driver.MySQLDriver.api._
import play.api.db.slick.DatabaseConfigProvider
import slick.backend.DatabaseConfig
import scala.concurrent.Future
case class Restaurante (var id:Int,var nombre:String,var direccion:String)
class RestauranteTableDef(tag: Tag) extends Table[Restaurante](tag, "Restaurantes") {
def id = column[Int]("id", O.PrimaryKey,O.AutoInc)
def nombre = column[String]("Nombre")
def direccion = column[String]("Direccion")
override def * =
(id, nombre, direccion) <>(Restaurante.tupled, Restaurante.unapply)
}
class Restaurantes @Inject() (appProvider: Provider[Application]) {
def dbConfig(): DatabaseConfig[JdbcProfile] =
DatabaseConfigProvider.get[JdbcProfile](appProvider.get())
val restaurantes = TableQuery[RestauranteTableDef]
var lista :List[Restaurante]={
List(
Restaurante(
3
,"La casa blanca"
,"Argentina"
),
Restaurante(
4
,"La casa rosta"
,"Manizales"
)
)
}
def adicionar(restaurante: Restaurante)={
lista = lista ::: List(restaurante)
}
def traerTodo:Future[Seq[Restaurante]]={
dbConfig().db.run(restaurantes.result)
}
}
开发者ID:arbeyvillegas,项目名称:Restaurante,代码行数:55,代码来源:Restaurante.scala
示例20: PlayApp
//设置package包名称以及导入依赖的类
import play.api.{Application, ApplicationLoader, Environment, Mode, Play}
import play.core.server.{ServerConfig, ServerProvider}
object PlayApp extends App {
val config = ServerConfig(mode = Mode.Dev)
val application: Application = {
val environment = Environment(config.rootDir, this.getClass.getClassLoader, Mode.Dev)
val context = ApplicationLoader.createContext(environment)
val loader = ApplicationLoader(context)
loader.load(context)
}
Play.start(application)
val serverProvider: ServerProvider = ServerProvider.fromConfiguration(this.getClass.getClassLoader, config.configuration)
serverProvider.createServer(config, application)
}
开发者ID:mindfulmachines,项目名称:unus,代码行数:20,代码来源:PlayApp.scala
注:本文中的play.api.Application类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论