1 2 | ./gradlew build java -jar build/libs/spring-boot-scala-web- 0.1 . 0 .jar |
Spring boot comes with a gradle based plugin which should have allowed the project to run with a "gradle bootRun" command, this unfortunately gives an error for scala based projects.
EDIT: This is actually not completely true, another way to run the Spring-boot code using gradle will be to use the gradle application plugin and specify the main program this way:
1 2 | apply plugin: 'application' mainClassName = "mvctest.SampleWebApplication" |
A good workaround is to use sbt for building and running Spring-boot based projects. The catch though is that with gradle and maven, the versions of the dependencies would have been managed through a parent pom, now these have to be explicitly specified. This is how a sample sbt build file with the dependencies spelled out looks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | name := "spring-boot-scala-web" version := "1.0" scalaVersion := "2.10.4" sbtVersion := "0.13.1" seq(webSettings : _*) libraryDependencies ++= Seq( "org.springframework.boot" % "spring-boot-starter-web" % "1.0.2.RELEASE" , "org.springframework.boot" % "spring-boot-starter-data-jpa" % "1.0.2.RELEASE" , "org.webjars" % "bootstrap" % "3.1.1" , "org.webjars" % "jquery" % "2.1.0-2" , "org.thymeleaf" % "thymeleaf-spring4" % "2.1.2.RELEASE" , "org.hibernate" % "hibernate-validator" % "5.0.2.Final" , "nz.net.ultraq.thymeleaf" % "thymeleaf-layout-dialect" % "1.2.1" , "org.hsqldb" % "hsqldb" % "2.3.1" , "org.springframework.boot" % "spring-boot-starter-tomcat" % "1.0.2.RELEASE" % "provided" , "javax.servlet" % "javax.servlet-api" % "3.0.1" % "provided" ) libraryDependencies ++= Seq( "org.apache.tomcat.embed" % "tomcat-embed-core" % "7.0.53" % "container" , "org.apache.tomcat.embed" % "tomcat-embed-logging-juli" % "7.0.53" % "container" , "org.apache.tomcat.embed" % "tomcat-embed-jasper" % "7.0.53" % "container" ) |
Here I am also using xsbt-web-plugin which is plugin for building scala web applications.
xsbt-web-plugin also comes with commands to start-up tomcat or jetty based containers and run the applications within these containers, however I had difficulty in getting these to work.
What worked is the runMain command to start up the Spring-boot main program through sbt:
1 | runMain mvctest.SampleWebApplication |
and xsbt-web-plugin allows the project to be packaged as a war file using the "package" command, this war deploys and runs without any issues in a standalone tomcat container.
Here is a github project with these changes: https://github.com/bijukunjummen/spring-boot-scala-web.git