当前位置: 首页>>代码示例>>Scala>>正文


Scala ApplicationLoader类代码示例

本文整理汇总了Scala中play.api.ApplicationLoader的典型用法代码示例。如果您正苦于以下问题:Scala ApplicationLoader类的具体用法?Scala ApplicationLoader怎么用?Scala ApplicationLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ApplicationLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: CustomApplicationLoader

//设置package包名称以及导入依赖的类
package modules

import play.api.ApplicationLoader
import play.api.Configuration
import play.api.inject._
import play.api.inject.guice._
import play.api.ApplicationLoader.Context
import com.typesafe.config.ConfigFactory
import play.api.Mode._
import play.Logger

class CustomApplicationLoader extends GuiceApplicationLoader {

  override protected def builder(context: Context): GuiceApplicationBuilder = {
    val builder = initialBuilder.in(context.environment).overrides(overrides(context): _*)
    context.environment.mode match {
      case Prod => {
        // start mode
        val prodConf = Configuration(ConfigFactory.load("prod.conf"))
        builder.loadConfig(prodConf ++ context.initialConfiguration)
      }
      case Dev => {
        Logger.error("*** Custom Loader DEV****")
        // run mode
        val devConf = Configuration(ConfigFactory.load("dev.conf"))
        builder.loadConfig(devConf ++ context.initialConfiguration)
      }
      case Test => {
        Logger.error("*** Custom Loader TEST ****")
        // test mode
        val testConf = Configuration(ConfigFactory.load("test.conf"))
        builder.loadConfig(testConf ++ context.initialConfiguration)
      }
    }
  }
} 
开发者ID:Driox,项目名称:play-app-seed,代码行数:37,代码来源:CustomApplicationLoader.scala

示例2: WebGateway

//设置package包名称以及导入依赖的类
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.softwaremill.macwire._
import controllers.{Assets, Main}
import ogr.wex.cmsfs.monitor.api.MonitorService
import org.wex.cmsfs.lagom.service.discovery.Common
import org.wex.cmsfs.lagom.service.discovery.consul.ConsulServiceLocatorComponents
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import router.Routes

import scala.collection.immutable
import scala.concurrent.ExecutionContext

abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
  with I18nComponents
  with AhcWSComponents
  with LagomServiceClientComponents {

  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "web-gateway",
    Map(
      "web-gateway" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val monitorService = serviceClient.implement[MonitorService]
  lazy val main = wire[Main]
  lazy val assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context) = {
    Common.loaderEnvironment(context)
    println(context.environment.mode)

    context.environment.mode match {
      case Mode.Dev =>
        new WebGateway(context) with LagomDevModeComponents {}.application
      case _ =>
        new WebGateway(context) with ConsulServiceLocatorComponents {}.application
    }
  }
} 
开发者ID:shinhwagk,项目名称:cmsfs,代码行数:53,代码来源:Loader.scala

示例3: 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

示例4: Boot

//设置package包名称以及导入依赖的类
package boot

import controllers.DevicesController
import play.api.ApplicationLoader.Context
import play.api.db.evolutions.EvolutionsComponents
import play.api.db.slick.evolutions.SlickEvolutionsComponents
import play.api.db.slick.{DbName, DefaultSlickApi}
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
import play.filters.HttpFiltersComponents
import router.Routes
import services.DataSource
import slick.basic.DatabaseConfig
import services.DataSourceJdbc
import slick.jdbc.JdbcProfile

class Boot extends ApplicationLoader {
  def load(context: Context): Application = {
    val components = new BootComponents(context)
    components.applicationEvolutions // Run the evolutions
    components.application
  }
}

class BootComponents(context: Context)
  extends BuiltInComponentsFromContext(context)
    with HttpFiltersComponents
    with controllers.AssetsComponents
    with EvolutionsComponents
    with SlickEvolutionsComponents {

  override def api: DefaultSlickApi = new DefaultSlickApi(environment, configuration, applicationLifecycle)
  private[this] val defaultDBName: DbName = DbName("devices")
  private[this] val dbConfig: DatabaseConfig[JdbcProfile] = slickApi.dbConfig[JdbcProfile](defaultDBName)

  // TODO put this into config
  private[this] val dbPoolSize = 10
  private[this] lazy val dataSource: DataSource = new DataSourceJdbc(dbConfig, dbPoolSize)
  private[this] lazy val devicesController: DevicesController = new DevicesController(controllerComponents, dataSource)
  override lazy val router: Routes = new Routes(httpErrorHandler, devicesController, assets)
} 
开发者ID:openada,项目名称:adaweather,代码行数:41,代码来源:Boot.scala

示例5: DevicesControllerHtmlSpec

//设置package包名称以及导入依赖的类
package controllers

import boot.Boot
import mocks.DataSourceMock
import org.scalatestplus.play._
import play.api.test.Helpers._
import play.api.test._
import play.api.{ApplicationLoader, Environment}

class DevicesControllerHtmlSpec extends PlaySpec {

  "DevicesController GET" should {

    "render the index page from a new instance of controller" in {
      val controller = new DevicesController(stubControllerComponents(), DataSourceMock.mockDevices)
      val home = controller.getDevicesAsHTML.apply(FakeRequest(GET, "/"))

      status(home) mustBe OK
      contentType(home) mustBe Some("text/html")
      contentAsString(home) must include ("Ada weather")
    }

    "render the index page from the router" in {
      val context = ApplicationLoader.createContext(Environment.simple())
      val app = new Boot().load(context)
      val request = FakeRequest(GET, "/")
      val home = route(app, request).get

      status(home) mustBe OK
      contentType(home) mustBe Some("text/html")
      contentAsString(home) must include ("Ada weather")
    }
  }
} 
开发者ID:openada,项目名称:adaweather,代码行数:35,代码来源:DevicesControllerHtmlSpec.scala

示例6: AppComponent

//设置package包名称以及导入依赖的类
import com.typesafe.config.Config
import controllers.{ OAuthGitHubController, TEAHubController, UIController }
import play.api.{ Application, ApplicationLoader, BuiltInComponentsFromContext, LoggerConfigurator }
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.libs.ws.ahc.AhcWSClient
import play.api.i18n._
import services.impl.{ ApiGitHubService, ApiOAuthGitHubService, ApiTogglService }
import scala.concurrent.{ ExecutionContext, Future }
import router.Routes


class AppComponent(context: Context)(implicit val ec: ExecutionContext) extends BuiltInComponentsFromContext(context)
    with EhCacheComponents with I18nComponents {

  val config: Config = context.initialConfiguration.underlying
  val wsClient = AhcWSClient()

  lazy val oauthGitHubService = new ApiOAuthGitHubService(config, wsClient)
  lazy val oauthGitHubController = new OAuthGitHubController(oauthGitHubService)
  lazy val gitHubService = new ApiGitHubService(wsClient)
  lazy val togglService = new ApiTogglService(wsClient)
  lazy val teahubController = new TEAHubController(togglService, gitHubService, defaultCacheApi)
  lazy val assetsController = new controllers.Assets(httpErrorHandler)
  lazy val uiController = new UIController(messagesApi, defaultCacheApi, teahubController)(ec)

  lazy val router = new Routes(
    httpErrorHandler,
    oauthGitHubController,
    uiController,
    teahubController,
    assetsController
  )

  applicationLifecycle.addStopHook(() => Future.successful(wsClient.close))
} 
开发者ID:lunatech-labs,项目名称:teahub,代码行数:37,代码来源:AppLoader.scala

示例7: TestUserClient

//设置package包名称以及导入依赖的类
package test

import scala.concurrent.{ExecutionContext, Future}
import play.api.{ApplicationLoader, Environment}
import play.api.ApplicationLoader.Context

import clients._
import init.ApplicationComponents
import models.User

class TestUserClient(
  users: (Int, User)*
) extends UserClient {

  private val usersMap = Map(users:_*)

  def getUser(id: Int)(implicit ec: ExecutionContext): Future[Option[User]] = {
    Future.successful(usersMap.get(id))
  }

}

class TestApplicationComponents(
  context: Context = ApplicationLoader.createContext(Environment.simple()),
  val userClient: UserClient
) extends ApplicationComponents(context)
  with ClientComponents 
开发者ID:EVENFinancial,项目名称:play-compile-time-di-example,代码行数:28,代码来源:Helpers.scala

示例8: WebGateway

//设置package包名称以及导入依赖的类
import com.example.auction.bidding.api.BiddingService
import com.example.auction.item.api.ItemService
import com.example.auction.user.api.UserService
import com.lightbend.lagom.scaladsl.api.{ ServiceAcl, ServiceInfo }
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents
import controllers.{ Assets, ItemController, Main, ProfileController }
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{ ApplicationLoader, BuiltInComponentsFromContext, Mode }
import router.Routes

import scala.collection.immutable
import scala.concurrent.ExecutionContext

abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
  with I18nComponents
  with AhcWSComponents
  with LagomServiceClientComponents {

  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "web-gateway",
    Map(
      "web-gateway" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val userService = serviceClient.implement[UserService]
  lazy val itemService = serviceClient.implement[ItemService]
  lazy val biddingService = serviceClient.implement[BiddingService]

  lazy val main = wire[Main]
  lazy val itemController = wire[ItemController]
  lazy val profileController = wire[ProfileController]
  lazy val assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context) = context.environment.mode match {
    case Mode.Dev =>
      (new WebGateway(context) with LagomDevModeComponents).application
    case _ =>
      (new WebGateway(context) with ConductRApplicationComponents).application
  }
} 
开发者ID:lagom,项目名称:online-auction-scala,代码行数:54,代码来源:Loader.scala

示例9: Loader

//设置package包名称以及导入依赖的类
package com.thoughtworks.microbuilder.tutorial.organizationBff

import com.thoughtworks.microbuilder.play.{RpcEntry, PlayOutgoingJsonService, RpcController}
import com.thoughtworks.microbuilder.tutorial.githubSdk.proxy.MicrobuilderOutgoingProxyFactory._
import com.thoughtworks.microbuilder.tutorial.githubSdk.proxy.MicrobuilderRouteConfigurationFactory._
import com.thoughtworks.microbuilder.tutorial.organizationBffSdk.proxy.MicrobuilderIncomingProxyFactory._
import com.thoughtworks.microbuilder.tutorial.organizationBffSdk.proxy.MicrobuilderRouteConfigurationFactory._
import com.thoughtworks.microbuilder.tutorial.githubSdk.rpc.IOrganizationService
import com.thoughtworks.microbuilder.tutorial.organizationBffSdk.rpc.IOrganizationBffService
import play.api.libs.ws.ning.NingWSComponents
import play.api.{BuiltInComponentsFromContext, Application, ApplicationLoader}
import play.api.ApplicationLoader.Context
import router.Routes


class Loader extends ApplicationLoader {
  override def load(context: Context): Application = {

    val components = new BuiltInComponentsFromContext(context) with NingWSComponents {
      implicit def executionContext = actorSystem.dispatcher

      lazy val organizationService = PlayOutgoingJsonService.newProxy[IOrganizationService]("https://api.github.com/", wsApi)

      lazy val bffService = new OrganizationBffService(organizationService)

      lazy val rpcController = new RpcController(Seq(RpcEntry.implementedBy[IOrganizationBffService](bffService)))

      override lazy val router = new Routes(httpErrorHandler, rpcController)
    }

    components.application
  }
} 
开发者ID:Atry,项目名称:organization-bff,代码行数:34,代码来源:Loader.scala

示例10: GrimeyAppLoader

//设置package包名称以及导入依赖的类
package com.grimey

import com.grimey.staticpage.StaticPageService
import controllers.{AdminController, HomeController, Assets, StaticPageController}

import play.api.ApplicationLoader.Context
import play.api.routing.Router
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
import router.Routes
import play.api.i18n.{DefaultMessagesApi, DefaultLangs, MessagesApi, I18nSupport}
import play.api.Play.current

import scala.concurrent.Future
import scala.concurrent.duration.Duration

class GrimeyAppLoader extends ApplicationLoader {
  override def load(context: Context): Application = new GrimeyAppComponents(context).application
}

class GrimeyAppComponents(context: Context) extends BuiltInComponentsFromContext(context) with I18nSupport {
  val config = current.configuration // Todo: Inject this.

  lazy val db = new GrimeyDatabaseContext(DatabaseContextConfig(
    Duration(config.getString("grimey.db.defaultTimeoutInMs").getOrElse("10000")))).db

  lazy val staticPageService = new StaticPageService(db)

  lazy val homeController = new HomeController()
  lazy val adminController = new AdminController()
  lazy val staticPageController = new StaticPageController(staticPageService, messagesApi())
  lazy val assetsController = new Assets(httpErrorHandler)

  applicationLifecycle.addStopHook(() => Future.successful(db.close()))

  override def router: Router = new Routes(httpErrorHandler, homeController, adminController, staticPageController,
    assetsController)

  override def messagesApi(): MessagesApi = new DefaultMessagesApi(environment, configuration, new DefaultLangs(configuration))
}

case class DatabaseContextConfig(defaultTimeout: Duration) 
开发者ID:CSGrimey,项目名称:grimey-cms-scala,代码行数:42,代码来源:GrimeyAppLoader.scala

示例11: TestAppComponents

//设置package包名称以及导入依赖的类
package com.grimey.utils

import java.io.File

import com.grimey.{DatabaseContextConfig, GrimeyDatabaseContext, GrimeyAppComponents}
import play.api
import play.api.{Mode, Environment, ApplicationLoader}
import play.api.ApplicationLoader.Context
import scala.concurrent.duration._
import slick.jdbc.JdbcBackend

trait TestUtils {
  // Todo: This should be injected.
  protected lazy val db: JdbcBackend#DatabaseDef =
    new GrimeyDatabaseContext(DatabaseContextConfig(defaultTimeout = 10.seconds)).db

  implicit lazy val app: api.Application = {
    val appLoader = new TestAppLoader()
    val context = ApplicationLoader.createContext(
      new Environment(new File("."), ApplicationLoader.getClass.getClassLoader, Mode.Test)
    )

    appLoader.load(context)
  }
}

class TestAppComponents(context: Context) extends GrimeyAppComponents(context) {
  // Todo: Add test specific configuration here when applicable.
}

class TestAppLoader extends ApplicationLoader {
  override def load(context: Context): api.Application = new TestAppComponents(context).application
} 
开发者ID:CSGrimey,项目名称:grimey-cms-scala,代码行数:34,代码来源:TestUtils.scala

示例12: WebGateway

//设置package包名称以及导入依赖的类
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.ApplicationLoader.Context
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import router.Routes
import com.softwaremill.macwire._
import controllers.Assets
import uk.co.turingatemyhamster.shoppinglist.user.api.UserService

import scala.collection.immutable
import scala.concurrent.ExecutionContext

abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
                                                    with I18nComponents
                                                    with AhcWSComponents
                                                    with LagomServiceClientComponents
{
  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "web-ui",
    Map(
      "web-ui" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )

  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher

  protected implicit lazy val playConfig = context.initialConfiguration
  protected implicit lazy val playEnv = context.environment

  override lazy val router: Routes = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val userService = serviceClient.implement[UserService]

  lazy val cApplication: controllers.Application = wire[controllers.Application]
  lazy val assets: Assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context) = context.environment.mode match {
    case Mode.Dev =>
      new WebGateway(context) with LagomDevModeComponents {}.application
    case _ =>
      new WebGateway(context) {
        override def serviceLocator = NoServiceLocator
      }.application
  }
} 
开发者ID:drdozer,项目名称:shoppinglist,代码行数:55,代码来源:Loader.scala

示例13: EmailService

//设置package包名称以及导入依赖的类
package utils


import play.api.{ BuiltInComponentsFromContext, ApplicationLoader }
import play.api.ApplicationLoader.Context
import play.api.inject.guice.GuiceApplicationBuilder
import javax.inject.Inject
import play.api.libs.mailer._
import java.io.File
import org.apache.commons.mail.EmailAttachment

class EmailService @Inject() (val mailerClient: MailerClient) {

  def sendEmail(subject: String, senderName: String, senderEmail: String, receiverName: String, receiverEmail: String, contentHTML: String) = {

    val email = Email(
      subject,
      s"""$senderName <$senderEmail>""",
      Seq(s"""$receiverName <$receiverEmail>"""),
      bodyHtml = Some(s"""$contentHTML""")
    )
    mailerClient.send(email)
  }

} 
开发者ID:elarib,项目名称:cvManager,代码行数:26,代码来源:EmailService.scala

示例14: MyComponents

//设置package包名称以及导入依赖的类
package com.svitovyda

import akka.actor.ActorSystem
import com.svitovyda.configuration.ConfigurationsComponents
import play.api.{ApplicationLoader, BuiltInComponentsFromContext}
import play.api.ApplicationLoader.Context
import play.api.routing.Router
import com.svitovyda.counter.CounterComponents
import com.svitovyda.router.RouterComponents


class MyComponents(context: Context) {
  import MyComponents._

  lazy val counter = new CounterComponents

  lazy val configurations = new ConfigurationsComponents

  lazy val router = new RouterComponents(counter, configurations)

  lazy val play = new Play(context, () => router.router)
}
object MyComponents {

  val actorSystem = ActorSystem()

  class Play(
      context: ApplicationLoader.Context,
      createRouter: () => Router)
    extends BuiltInComponentsFromContext(context) {

    lazy val router: Router = createRouter()
    override lazy val actorSystem: ActorSystem = MyComponents.actorSystem
  }
} 
开发者ID:svitovyda,项目名称:scala-play254,代码行数:36,代码来源:MyComponents.scala

示例15: MockedApplication

//设置package包名称以及导入依赖的类
import org.openqa.selenium.WebDriver
import play.api.test._
import play.api.{ApplicationLoader, Environment, Mode}

class MockedApplication
    extends WithApplicationLoader(
      new MockedApplicationLoader)

class MockedApplicationWithBrowser[W <: WebDriver]
    extends WithBrowser[W](
      app = new MockedApplicationLoader().load(
        ApplicationLoader.createContext(
          new Environment(
            new java.io.File("."),
            ApplicationLoader.getClass.getClassLoader,
            Mode.Test)))) 
开发者ID:leanovate,项目名称:contoso-conference-manager,代码行数:17,代码来源:MockedApplication.scala


注:本文中的play.api.ApplicationLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。