Web Application using Spring Tool Suite,Gradle and Scala
Step 1: Install Gradle on your windows system.
Download link: http://gradle.org/ (version 2.2.1)
Set the Path environment variable to: your path\gradle-2.2.1-all\gradle-2.2.1\bin
Step 2: Install Scala on your system.
Download Link: http://www.scala-lang.org/download/ (version 2.11.4)
As above set the Path environment variable to : C:\Program Files\scala\bin;
Step 4: clone this Hello-World github code in your system
Link : git clone https://github.com/vaibhavtupe/hello-world
Important files:
build.gradle
Mention your gradle version correctly in this file.
And also mention spring boot application main class file.
HelloWebApplication.scala
And also mention spring boot application main class file.
buildscript {
repositories {
maven { url "http://repo.spring.io/release" }
mavenCentral()
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'scala'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'hello'
version = '0.1.0'
}
bootRepackage {
mainClass = 'hello.HelloWebApplication'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/release" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.2.1.RELEASE")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile("org.scala-lang:scala-library:2.11.4")
compile("org.webjars:bootstrap:3.1.1")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2.1'
}
HelloWebApplication.scala
package hello import org.springframework.boot.SpringApplication import org.springframework.context.annotation._ import org.springframework.boot.autoconfigure.EnableAutoConfiguration /** * This object bootstraps Spring Boot web application. * Via Gradle: gradle bootRun * * @author vaibhav * @since 1.0 */ @EnableAutoConfiguration object HelloWebApplication { def main(args: Array[String]) { SpringApplication.run(classOf[HelloConfig]); } }
HelloConfig.scala
package hello import org.springframework.context.annotation.{Configuration, ComponentScan} import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.stereotype.Controller; /** * This config class will trigger Spring @annotation scanning and auto configure Spring context. * * @author vaibhav * @since 1.0 */ @Controller @Configuration @EnableAutoConfiguration @ComponentScan class HelloConfig { @RequestMapping(Array("/")) @ResponseBody def home(): String = "Hello World!" }
Step 5 : Go to the cloned directory hello-world/Hello-Scala from command prompt
Now do
gradle build
After successful build,
gradle run
Step 6 : Check the browser localhost:8080
Step 7 : Now same thing we can do on AWS EC2 instance using putty,
Download and install gradle, scala on EC2 instance
Do step 4 an step 5 again on EC2 instance.
Step 8 : Now go in your local machine browser and hit the URL
Your EC2 instance public DNS:8080
You have successfully created simple hello-world web application using spring tool suite and deployed it on Amazon EC2 instance.




Comments
Post a Comment