Spring Boot using Gradle
Sample Hello Spring Boot! Example using Gradle
Reffernce:-
1) http://www.bogotobogo.com/Java/tutorials/Spring-Boot/Spring-Boot-HelloWorld-with-Gradle.php
Installation Of Gradle
->open springsoot(sts)
help->EclipseMarketPlace->type gradle in find input box->click go->
select (Gradle (Sts) Integration for Eclips3.7.3. Release)-> click install
Downloading Gradle Project:-
open given link http://start.spring.io/
->select gradle project in “Generate a” in respectes link and click Generate Project alt button
-> then demo project will downloaded in our system.
Importing Gradle demo project in Springshoot(Sts)
file->import->Gradle(STS) project->next->click on Build Model->finish
2)create gradle.properties file in that project and paste below code
springBootVersion = 1.3.5.RELEASE
3)open build.gradle file and copy Gradle : Hello Spring Boot!below code
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(“org.springframework.boot:spring-boot-gradle–plugin:${springBootVersion}”)
}
}
apply plugin: ‘java’
apply plugin: ‘eclipse’
apply plugin: ‘idea’
apply plugin: ‘spring-boot’
jar {
baseName = ‘gs-spring-boot’
version = ‘0.1.0’
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
// tag::jetty[]
compile(“org.springframework.boot:spring-boot-starter-web”) {
exclude module: “spring-boot-starter-tomcat“
testCompile(‘org.springframework.boot:spring-boot-starter-test’)
}
compile(“org.springframework.boot:spring-boot-starter-jetty“)
// end::jetty[]
// tag::actuator[]
compile(“org.springframework.boot:spring-boot-starter-actuator”)
// end::actuator[]
testCompile(“junit:junit”)
}
task wrapper(type: Wrapper) {
gradleVersion = ‘2.11’
}
4)Right Click demo project->Gradle (STS)->click on Refresh Dependencies
5)Right Click demo project->Gradle (STS)->click on Refresh all
6)goto Run->Run Configurations
i)click Spring Boot tab and provide below information
Name:DEMO
Main type:com.example.DemoApplication
profile:dev
ii)click (x)=Arguments tab and provide below information
VM arguments: -Dserver.port=8083
Create HelloController
package com.example;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping(“/”)
public String index() {
return “Gradle : Hello Spring Boot!”;
}
}
create DemoApplication
package com.example;
import java.util.Arrays;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
ApplicationContext ctx =SpringApplication.run(DemoApplication.class, args);
System.out.println(“Let’s inspect the beans provided by Spring Boot:”);
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(“beanSR:”+beanName);
}
}
}
Start Server Run->select DEMO
and open browser and give the below url http://localhost:8083/
ouput: Gradle : Hello Spring Boot!
Spring Boot using maven