From ac415096dee06110ebe5536dbd3c5c86d06de4fe Mon Sep 17 00:00:00 2001 From: Mateusz Owczarek Date: Wed, 8 Jan 2020 14:32:28 +0100 Subject: [PATCH 1/4] Removed Spring from the dependencies, services are created now in Launcher --- .../g8/backend/src/main/resources/beans.conf | 11 ---------- .../backend/src/main/resources/services.conf | 22 ------------------- .../scala/$package$/backend/Launcher.scala | 14 +++++++++--- .../backend/services/RpcClientsService.scala | 5 +---- .../backend/spring/SpringContext.scala | 16 -------------- src/main/g8/project/Dependencies.scala | 9 ++------ 6 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 src/main/g8/backend/src/main/resources/beans.conf delete mode 100644 src/main/g8/backend/src/main/resources/services.conf delete mode 100644 src/main/g8/backend/src/main/scala/$package$/backend/spring/SpringContext.scala diff --git a/src/main/g8/backend/src/main/resources/beans.conf b/src/main/g8/backend/src/main/resources/beans.conf deleted file mode 100644 index 49f56f3..0000000 --- a/src/main/g8/backend/src/main/resources/beans.conf +++ /dev/null @@ -1,11 +0,0 @@ -include "application.conf" -include "services.conf" - -beans { - uiServer = { - %class = $package$.backend.server.ApplicationServer, %construct = true - port = \${server.port} - resourceBase = \${server.statics} - domainServices.%ref = domainServices - } -} diff --git a/src/main/g8/backend/src/main/resources/services.conf b/src/main/g8/backend/src/main/resources/services.conf deleted file mode 100644 index 350ec59..0000000 --- a/src/main/g8/backend/src/main/resources/services.conf +++ /dev/null @@ -1,22 +0,0 @@ -beans { - rpcClientsService = { - %class = $package$.backend.services.SpringRpcClientsService, %construct = true - } - - authService = { - %class = $package$.backend.services.AuthService, %construct = true - usersData = \${auth.users} - } - - chatService = { - %class = $package$.backend.services.ChatService, %construct = true - rpcClientsService.%ref = rpcClientsService - } - - domainServices = { - %class = $package$.backend.services.DomainServices, %construct = true - authService.%ref = authService - chatService.%ref = chatService - rpcClientsService.%ref = rpcClientsService - } -} diff --git a/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala b/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala index 9d6bbb4..42e46a3 100644 --- a/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala +++ b/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala @@ -2,8 +2,9 @@ package $package$.backend import java.util.concurrent.TimeUnit +import com.typesafe.config.{Config, ConfigFactory} import $package$.backend.server.ApplicationServer -import $package$.backend.spring.SpringContext +import $package$.backend.services.{AuthService, ChatService, DomainServices, RpcClientsService} import io.udash.logging.CrossLogging import scala.io.StdIn @@ -12,8 +13,15 @@ object Launcher extends CrossLogging { def main(args: Array[String]): Unit = { val startTime = System.nanoTime - val ctx = SpringContext.createApplicationContext("beans.conf") - val server = ctx.getBean(classOf[ApplicationServer]) + val config: Config = ConfigFactory.load() + val rpcClientsService: RpcClientsService = new RpcClientsService(RpcClientsService.defaultSendToClientFactory) + val authService: AuthService = new AuthService(config.getStringList("auth.users")) + val chatService: ChatService = new ChatService(rpcClientsService) + val server = new ApplicationServer( + config.getInt("server.port"), + config.getString("server.statics"), + new DomainServices()(authService, chatService, rpcClientsService) + ) server.start() val duration: Long = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime - startTime) diff --git a/src/main/g8/backend/src/main/scala/$package$/backend/services/RpcClientsService.scala b/src/main/g8/backend/src/main/scala/$package$/backend/services/RpcClientsService.scala index 60c0e3e..e24492e 100644 --- a/src/main/g8/backend/src/main/scala/$package$/backend/services/RpcClientsService.scala +++ b/src/main/g8/backend/src/main/scala/$package$/backend/services/RpcClientsService.scala @@ -49,7 +49,4 @@ object RpcClientsService { import scala.concurrent.ExecutionContext.Implicits.global (target: ClientRPCTarget) => new DefaultClientRPC[MainClientRPC](target).get } -} - -/** Class with default factory for Spring configuration. */ -private class SpringRpcClientsService() extends RpcClientsService(RpcClientsService.defaultSendToClientFactory) \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/g8/backend/src/main/scala/$package$/backend/spring/SpringContext.scala b/src/main/g8/backend/src/main/scala/$package$/backend/spring/SpringContext.scala deleted file mode 100644 index 1e14e97..0000000 --- a/src/main/g8/backend/src/main/scala/$package$/backend/spring/SpringContext.scala +++ /dev/null @@ -1,16 +0,0 @@ -package $package$.backend.spring - -import com.avsystem.commons.spring.HoconBeanDefinitionReader -import com.typesafe.config.ConfigFactory -import org.springframework.context.support.GenericApplicationContext - -object SpringContext { - /** Reads system configuration from "beans.conf" file. */ - def createApplicationContext(configName: String): GenericApplicationContext = { - val ctx = new GenericApplicationContext() - val bdr = new HoconBeanDefinitionReader(ctx) - bdr.loadBeanDefinitions(ConfigFactory.load(configName)) - ctx.refresh() - ctx - } -} diff --git a/src/main/g8/project/Dependencies.scala b/src/main/g8/project/Dependencies.scala index bb7a558..79b3182 100644 --- a/src/main/g8/project/Dependencies.scala +++ b/src/main/g8/project/Dependencies.scala @@ -12,8 +12,8 @@ object Dependencies { // Backend val avsystemCommonsVersion = "1.39.0" val jettyVersion = "9.4.20.v20190813" - val springVersion = "4.3.25.RELEASE" val logbackVersion = "1.2.3" + val typesafeConfigVersion = "1.4.0" // JS dependencies val bootstrapVersion = "4.1.3" @@ -85,12 +85,7 @@ object Dependencies { "org.eclipse.jetty" % "jetty-rewrite" % jettyVersion, "org.eclipse.jetty.websocket" % "websocket-server" % jettyVersion, - "org.springframework" % "spring-core" % springVersion, - "org.springframework" % "spring-beans" % springVersion, - "org.springframework" % "spring-context-support" % springVersion, - - // support for HOCON beans configuration - "com.avsystem.commons" %% "commons-spring" % avsystemCommonsVersion, + "com.typesafe" % "config" % typesafeConfigVersion, // server logging backend "ch.qos.logback" % "logback-classic" % logbackVersion, From a7aeae3154233ca3575a9fbbabf93d8681ac69c9 Mon Sep 17 00:00:00 2001 From: Mateusz Owczarek Date: Wed, 8 Jan 2020 14:32:55 +0100 Subject: [PATCH 2/4] Updated main and backend READMEs --- src/main/g8/README.md | 4 ++-- src/main/g8/backend/README.md | 21 +++++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/g8/README.md b/src/main/g8/README.md index 69d953f..ce1edaf 100644 --- a/src/main/g8/README.md +++ b/src/main/g8/README.md @@ -53,8 +53,8 @@ can find another a README.md file describing its content. Briefly: * `shared` - contains a global model and a login of the application, it also keeps CSS styles definition and RPC interfaces; -* `backend` - holds the server-side logic, it uses [Spring](https://spring.io/) for DI and [Jetty](https://www.eclipse.org/jetty/) as the servlets container; -* `frontend` - keeps views and the client's application logic. +* `backend` - holds the server-side logic, it uses [Jetty](https://www.eclipse.org/jetty/) as the servlets container; +* `frontend` - keeps views and the client's application logic. Each module contains tests based on [ScalaTest](http://www.scalatest.org/) and [ScalaMock](http://scalamock.org/). The `frontend` and `shared` modules use [scalajs-env-selenium](https://github.com/scala-js/scala-js-env-selenium) in order diff --git a/src/main/g8/backend/README.md b/src/main/g8/backend/README.md index babd6c3..dc5ca69 100644 --- a/src/main/g8/backend/README.md +++ b/src/main/g8/backend/README.md @@ -8,14 +8,13 @@ You can find five main packages in the sources of this module: * `$package$.backend.rpc` - an implementation of the server RPC interfaces. * `$package$.backend.server` - the code setting up [Jetty](https://www.eclipse.org/jetty/) with required servlets. * `$package$.backend.services` - services encapsulating the main business logic of the application. -* `$package$.backend.spring` - utilities handling [Spring](https://spring.io/) dependency injection. ## RPC and Services The main responsibility of the server application is to handle RPC calls from client applications. The implementation is separated into two layers: * RPC endpoints - created separately for each client connection which are a direct implementation of the RPC interfaces; -* services - created once as beans in the [Spring](https://spring.io/) application context. +* services - created once in the `Launcher` object. The endpoints are a good place to resolve `UserContext` or verify user's permissions. The services usually contain business logic reusable between endpoints and other entry points of the app e.g. REST API. @@ -24,21 +23,15 @@ Read more about the RPC interfaces in the [Udash Guide](http://guide.udash.io/#/ ## Server and configuration -This application uses [Spring](https://spring.io/) for dependency injection with an extension from -[AVSystem Commons](https://github.com/AVSystem/scala-commons), which allows us to write configuration -using the [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md) format. The configuration files are localized -in the resource bundles stored in `backend/src/main/resources`. This directory also contains translation bundles and basic +The configuration file (`application.conf`) contains application configuration variables e.g. the user list or the web +server port. It is stored in `backend/src/main/resources`. This directory also contains translation bundles and basic [Logback](https://logback.qos.ch/) configuration. -The application configuration is separated into three files: -* `application.conf` - application configuration variables e.g. the user list or the web server port. -* `beans.conf` - the main configuration file which contains web server bean definition. -* `services.conf` - definition of services beans. - -As you can see, the `Launcher` object loads configuration from `beans.conf` and starts `ApplicationServer`. +As you can see, the `Launcher` object loads configuration from `application.conf` using +[Typesafe Config](https://lightbend.github.io/config/), creates services and starts `ApplicationServer`. The `ApplicationServer` class creates two servlets: the first serves static files like compiled JS or CSS sources, -the second is responsible for handling WebSocket connections from the client applications. The aforementioned -servlets are registered in the [Jetty](https://www.eclipse.org/jetty/) server. +the second is responsible for handling WebSocket connections from the client applications. The aforementioned servlets +are registered in the [Jetty](https://www.eclipse.org/jetty/) server. Read more about bootstrapping the backend application in the [Udash Guide](http://guide.udash.io/#/bootstrapping/backend). From 757c2d2f9b0c83016d1e15ce4b0b361fa78d5a37 Mon Sep 17 00:00:00 2001 From: Mateusz Owczarek Date: Wed, 8 Jan 2020 15:29:56 +0100 Subject: [PATCH 3/4] updated sbt and sbt-giter8 version --- .travis.yml | 2 ++ project/build.properties | 5 +++-- project/plugins.sbt | 2 +- src/main/g8/default.properties | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index f479ff0..300d477 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ addons: chrome: stable language: scala +scala: + - 2.12.10 jdk: - openjdk11 diff --git a/project/build.properties b/project/build.properties index f2de71f..7aa18c9 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1,2 +1,3 @@ -# suppress inspection "UnusedProperty" -sbt.version = 1.3.2 +# suppress inspection "UnusedProperty" for whole file +sbt.version = 1.3.6 +giter8.version=0.12.0 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index b731971..267b7e4 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.12.0-M2") +addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.12.0") diff --git a/src/main/g8/default.properties b/src/main/g8/default.properties index fa1f5ba..6c2a675 100644 --- a/src/main/g8/default.properties +++ b/src/main/g8/default.properties @@ -2,4 +2,4 @@ name = My Udash Application package = io.company.app scala_version = 2.12.10 udash_version = 0.8.1 -sbt_version = 1.2.8 +sbt_version = 1.3.6 From 0554bf47c598904722e66ac54fa7cd3819d865ce Mon Sep 17 00:00:00 2001 From: Mateusz Owczarek Date: Thu, 9 Jan 2020 13:13:49 +0100 Subject: [PATCH 4/4] implicits services in Launcher, removed avs-commons version from Deps --- .../src/main/scala/$package$/backend/Launcher.scala | 12 ++++-------- src/main/g8/project/Dependencies.scala | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala b/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala index 42e46a3..feb82b7 100644 --- a/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala +++ b/src/main/g8/backend/src/main/scala/$package$/backend/Launcher.scala @@ -14,14 +14,10 @@ object Launcher extends CrossLogging { val startTime = System.nanoTime val config: Config = ConfigFactory.load() - val rpcClientsService: RpcClientsService = new RpcClientsService(RpcClientsService.defaultSendToClientFactory) - val authService: AuthService = new AuthService(config.getStringList("auth.users")) - val chatService: ChatService = new ChatService(rpcClientsService) - val server = new ApplicationServer( - config.getInt("server.port"), - config.getString("server.statics"), - new DomainServices()(authService, chatService, rpcClientsService) - ) + implicit val rpcClientsService: RpcClientsService = new RpcClientsService(RpcClientsService.defaultSendToClientFactory) + implicit val authService: AuthService = new AuthService(config.getStringList("auth.users")) + implicit val chatService: ChatService = new ChatService(rpcClientsService) + val server = new ApplicationServer(config.getInt("server.port"), config.getString("server.statics"), new DomainServices) server.start() val duration: Long = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime - startTime) diff --git a/src/main/g8/project/Dependencies.scala b/src/main/g8/project/Dependencies.scala index 79b3182..348bd9d 100644 --- a/src/main/g8/project/Dependencies.scala +++ b/src/main/g8/project/Dependencies.scala @@ -10,7 +10,6 @@ object Dependencies { val udashJQueryVersion = "3.0.1" // Backend - val avsystemCommonsVersion = "1.39.0" val jettyVersion = "9.4.20.v20190813" val logbackVersion = "1.2.3" val typesafeConfigVersion = "1.4.0"