Skip to content

Commit

Permalink
Merge pull request #19 from UdashFramework/springPurge
Browse files Browse the repository at this point in the history
Removed Spring from the dependencies
  • Loading branch information
ddworak authored Jan 9, 2020
2 parents c13e8e2 + 0554bf4 commit 533f68c
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ addons:
chrome: stable

language: scala
scala:
- 2.12.10

jdk:
- openjdk11
Expand Down
5 changes: 3 additions & 2 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.12.0-M2")
addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.12.0")
4 changes: 2 additions & 2 deletions src/main/g8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 7 additions & 14 deletions src/main/g8/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).

Expand Down
11 changes: 0 additions & 11 deletions src/main/g8/backend/src/main/resources/beans.conf

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/g8/backend/src/main/resources/services.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,8 +13,11 @@ 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()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/g8/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 2 additions & 8 deletions src/main/g8/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ object Dependencies {
val udashJQueryVersion = "3.0.1"

// 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"
Expand Down Expand Up @@ -85,12 +84,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,
Expand Down

0 comments on commit 533f68c

Please sign in to comment.