(Go: >> BACK << -|- >> HOME <<)

SlideShare a Scribd company logo
Spring 
Boot 
By 
Bhagwat 
Kumar
Agenda 
• What 
and 
Why? 
• Key 
features 
of 
Spring 
boot 
• Prototyping 
using 
CLI. 
• Gradle 
primer 
• Managing 
profiles 
aka 
environment 
in 
grails 
• Using 
Spring 
data 
libraries 
e.g. 
MongoDB 
• Using 
GORM 
• Presentation 
layer 
• Using 
GSP 
2
What 
and 
why? 
• Its 
not 
a 
replacement 
for 
Spring 
framework 
but 
it 
presents 
a 
small 
surface 
area 
for 
users 
to 
approach 
and 
extract 
value 
from 
the 
rest 
of 
Spring. 
• Spring-­‐boot 
provides 
a 
quick 
way 
to 
create 
a 
Spring 
based 
application 
from 
dependency 
management 
to 
convention 
over 
configuration. 
• Grails 
3.0 
will 
be 
based 
on 
Spring 
Boot. 
image 
source 
: 
http://spring.io/blog/2013/08/06/spring-­‐boot-­‐simplifying-­‐spring-­‐for-­‐everyone 
3
Key 
Features 
• Stand-­‐alone 
Spring 
applications 
• No 
code 
generation/ 
No 
XML 
Config 
• Automatic 
configuration 
by 
creating 
sensible 
defaults 
• Starter 
dependencies 
• Structure 
your 
code 
as 
you 
like 
• Supports 
Gradle 
and 
Maven 
• Common 
non-­‐functional 
requirements 
for 
a 
"real" 
application 
– 
embedded 
servers, 
– 
security, 
metrics, 
health 
checks 
– 
externalised 
configuration
Rapid 
Prototyping 
: 
Spring 
CLI 
• Quickest 
way 
to 
get 
a 
spring 
app 
off 
the 
ground 
• Allows 
you 
to 
run 
groovy 
scripts 
without 
much 
boilerplate 
code 
• Not 
recommended 
for 
production 
Install using GVM 
$ gvm install springboot 
Running groovy scripts 
$ spring run app.groovy 
$ spring run --watch app.groovy 
$ spring test tests.groovy
A 
quick 
web 
application 
using 
spring 
boot 
app.groovy 
@Controller 
class 
Example 
{ 
@RequestMapping("/") 
@ResponseBody 
public 
String 
helloWorld() 
{ 
"Hello 
Spring 
boot 
audience!!!" 
} 
} 
$ 
spring 
run 
app.groovy
What 
Just 
happened? 
// 
import 
org.springframework.web.bind.annotation.Controller 
// 
other 
imports 
... 
// 
@Grab("org.springframework.boot:spring-­‐boot-­‐web-­‐starter:0.5.0") 
// 
@EnableAutoConfiguration 
@Controller 
class 
Example 
{ 
@RequestMapping("/") 
@ResponseBody 
public 
String 
hello() 
{ 
return 
"Hello 
World!"; 
} 
// 
public 
static 
void 
main(String[] 
args) 
{ 
// 
SpringApplication.run(Example.class, 
args); 
// 
} 
}
Starter 
POMs 
• One-­‐stop-­‐shop 
for 
all 
the 
Spring 
and 
related 
technology 
• A 
set 
of 
convenient 
dependency 
descriptors 
• Contain 
a 
lot 
of 
the 
dependencies 
that 
you 
need 
to 
get 
a 
project 
up 
and 
running 
quickly 
• All 
starters 
follow 
a 
similar 
naming 
pattern; 
– 
spring-­‐boot-­‐starter-­‐* 
• Examples 
– spring-­‐boot-­‐starter-­‐web 
– spring-­‐boot-­‐starter-­‐data-­‐rest 
– spring-­‐boot-­‐starter-­‐security 
– spring-­‐boot-­‐starter-­‐amqp 
– spring-­‐boot-­‐starter-­‐data-­‐jpa 
– spring-­‐boot-­‐starter-­‐data-­‐elasticsearch 
– spring-­‐boot-­‐starter-­‐data-­‐mongodb 
– spring-­‐boot-­‐starter-­‐actuator
Demo 
: 
Starter 
POMs 
@Grab('spring-­‐boot-­‐starter-­‐security') 
@Grab('spring-­‐boot-­‐starter-­‐actuator') 
@Controller 
class 
Example 
{ 
@RequestMapping("/") 
@ResponseBody 
public 
String 
helloWorld() 
{ 
return 
"Hello 
Audience!!!" 
} 
} 
//security.user.name 
: 
default 
'user' 
//security.user.password 
: 
see 
log 
for 
auto 
generated 
password 
//actuator 
endpoints: 
/beans, 
/health, 
/mappings, 
/metrics 
etc.
Building 
using 
Gradle 
10
Lets 
go 
beyond 
prototyping 
: 
Gradle 
Image 
source 
: 
http://www.drdobbs.com/jvm/why-­‐build-­‐your-­‐java-­‐projects-­‐with-­‐gradle/240168608
build.gradle 
task 
hello 
<< 
{ 
println 
"Hello 
!!!!" 
} 
task 
greet 
<<{ 
println 
"Welocome 
Mr. 
Kumar" 
} 
task 
intro(dependsOn: 
hello) 
<< 
{ 
println 
"I'm 
Gradle" 
} 
hello 
<< 
{ 
println 
"Hello 
extended!!!!" 
} 
greet.dependsOn 
hello, 
intro 
// 
gradle 
tasks 
:list 
all 
the 
available 
tasks 
// 
gradle 
intro 
:executes 
intro 
task 
// 
gradle 
-­‐q 
greet 
:bare 
build 
output 
// 
gradle 
-­‐-­‐daemon 
hello 
:subsequent 
execution 
will 
be 
fast
build.gradle 
: 
using 
plugin 
and 
adding 
dependencies 
apply 
plugin: 
"groovy" 
//look 
for 
sources 
in 
src/main/groovy 
folder 
//inherits 
java 
plugin: 
src/main/java 
folder 
// 
tasks 
compileJava, 
compileGroovy, 
build, 
clean 
sourceCompatibility 
= 
1.6 
repositories 
{ 
mavenCentral() 
} 
dependencies 
{ 
compile 
'org.codehaus.groovy:groovy-­‐all:2.3.6' 
compile 
"org.apache.commons:commons-­‐lang3:3.0.1" 
testCompile 
"junit:unit:4.+" 
}
build.gradle: 
for 
Spring 
boot 
app 
with 
hot 
reloading 
apply 
plugin: 
'groovy' 
apply 
plugin: 
'idea' 
apply 
plugin: 
'spring-­‐boot' 
buildscript 
{ 
repositories 
{ 
mavenCentral()} 
dependencies 
{ 
classpath("org.springframework.boot:spring-­‐boot-­‐gradle-­‐plugin:1.1.8.RELEASE") 
classpath 
'org.springframework:springloaded:1.2.0.RELEASE' 
} 
} 
idea 
{ 
module 
{ 
inheritOutputDirs 
= 
false 
outputDir 
= 
file("$buildDir/classes/main/") 
} 
} 
repositories 
{ 
mavenCentral() 
} 
dependencies 
{ 
compile 
'org.codehaus.groovy:groovy-­‐all' 
compile 
'org.springframework.boot:spring-­‐boot-­‐starter-­‐web' 
}
Environment 
and 
Profile 
aka 
Grails 
config 
• Put 
application.properties/application.yml 
somewhere 
in 
classpath 
• Easy 
one: 
src/main/resources 
folder 
15 
application.yml 
app: 
name: 
Springboot+Config+Yml+Demo 
version: 
1.0.0 
server: 
port: 
8080 
settings: 
counter: 
1 
-­‐-­‐-­‐ 
spring: 
profiles: 
development 
server: 
port: 
9001 
application.properties 
app.name=Springboot+Config+Demo 
app.version=1.0.0 
server.port=8080 
settings.coutner=1 
application-­‐development.properties 
app.name=Springboot+Config+Demo 
app.version=1.0.0 
server.port=8080
Binding 
properties 
16 
Using 
ConfigurationProperties 
annotation 
import 
org.springframework.boot.context.properties.ConfigurationProperties 
import 
org.springframework.stereotype.Component 
@Component 
@ConfigurationProperties(prefix 
= 
"app") 
class 
AppInfo 
{ 
String 
name 
String 
version 
} 
Using 
Value 
annotation 
import 
org.springframework.beans.factory.annotation.Value 
import 
org.springframework.stereotype.Component 
@Component 
class 
AppConfig 
{ 
@Value('${app.name}') 
String 
appName 
@Value('${server.port}') 
Integer 
port 
}
Examples 
17 
OS 
env 
variable 
export 
SPRING_PROFILES_ACTIVE=development 
export 
SERVER_PORT=8090 
gradle 
bootRun 
java 
-­‐jar 
build/libs/demo-­‐1.0.0.jar 
with 
a 
-­‐D 
argument 
(remember 
to 
put 
it 
before 
the 
main 
class 
or 
jar 
archive) 
java 
-­‐jar 
-­‐Dspring.profiles.active=development 
build/libs/dem-­‐1.0.0.jar 
java 
-­‐jar 
-­‐Dserver.port=8090 
build./libs/demo-­‐1.0.0.jar
Using 
Spring 
data 
• Add 
dependency 
compile 
'org.springframework.boot:spring-­‐boot-­‐starter-­‐data-­‐mongodb' 
• Configure 
database 
URL 
spring.data.mongodb.uri=mongodb://localhost/springtestdev 
• Add 
entity 
class 
import 
org.springframework.data.annotation.Id; 
class 
• Add 
Person{@Id 
String 
id, 
String 
name} 
repository 
interface 
import 
org.springframework.data.mongodb.repository.MongoRepository 
public 
interface 
PersonRepository 
extends 
• Autowire 
and 
use 
like 
charm 
MongoRepository<Person, 
String> 
{} 
@Autowired 
PersonRepository 
personRepository 
personRepository.save(new 
Person(name:'Spring 
Boot')) 
personRepository.findAll() 
personRepository.count()
Next 
level 
persistence 
with 
GORM 
• Add 
dependencies 
to 
use 
GORM-­‐Hibernate 
• For 
GORM 
MongoDB 
use 
the 
following 
dependencies 
compile 
'org.grails:gorm-­‐mongodb-­‐spring-­‐boot:1.1.0.RELEASE' 
• Add 
entity 
with 
@grails.persistence.entity 
19 
compile 
'org.springframework.boot:spring-­‐boot-­‐starter-­‐data-­‐jpa' 
compile 
'org.grails:gorm-­‐hibernate4-­‐spring-­‐boot:1.1.0.RELEASE' 
runtime 
'com.h2database:h2' 
//for 
h2 
database 
import 
grails.persistence.Entity 
@Entity 
class 
Person 
{ 
String 
name; 
Integer 
age 
static 
constraints 
= 
{ 
name 
blank: 
false 
age 
min: 
15 
} 
} 
Further 
reading 
https://github.com/grails/grails-­‐data-­‐mapping
Server 
side 
view 
template 
libraries 
• JSP/JSTL 
• Thymeleaf 
• Freemarker 
• Velocity 
• Tiles 
• GSP 
• Groovy 
Template 
Engine 
20
• Very 
limited 
existing 
tags 
available 
• https://github.com/grails/grails-­‐boot/issues/3 
• Add 
dependency 
• Put 
GSP 
templates 
in 
resources/templates 
folder 
GSP 
21 
compile 
"org.grails:grails-­‐gsp-­‐spring-­‐boot:1.0.0.RC1" 
compile 
"org.grails:grails-­‐web:2.4.0.M2"
GSP 
continued... 
• Sample 
request 
handler 
22 
@RequestMapping("/show/{id}") 
public 
ModelAndView 
show(@PathVariable 
Long 
id) 
{ 
Person 
person 
= 
Person.read(id) 
if 
(person) 
{ 
//render(view:"/person/show", 
model:[personInstance:personInstance]) 
new 
ModelAndView("/person/show", 
[personInstance: 
Person.get(id)]) 
} 
else 
{ 
log.info 
"No 
entity 
fount 
for 
id 
: 
" 
+ 
id 
//redirect(controller:"person", 
action:"list") 
new 
ModelAndView("redirect:/person/list") 
} 
}
Grails 
Taglib 
23 
@grails.gsp.TagLib 
@org.springframework.stereotype.Component 
class 
ApplicationTagLib 
{ 
static 
namespace 
= 
"app" 
def 
paginate 
= 
{ 
attrs 
-­‐> 
String 
action 
= 
attrs.action 
Integer 
total 
= 
attrs.total 
Integer 
currentPage 
= 
attrs.currentPage 
?: 
1 
Integer 
pages 
= 
(total 
/ 
10) 
+ 
1 
out 
<< 
render(template: 
"/shared/pagination", 
model: 
[action: 
action, 
total: 
total, 
currentPage: 
currentPage, 
pages: 
pages] 
) 
} 
} 
<app:paginate 
total="${personInstanceCount 
?: 
0}" 
currentPage="${currentPage}" 
action="/person/list"/>
Packaging 
executable 
jar 
and 
war 
files 
24 
Packaging 
as 
jar 
with 
embedded 
tomcat 
$ 
gradle 
build 
$ 
java 
-­‐jar 
build/libs/mymodule-­‐0.0.1-­‐SNAPSHOT.jar 
Packaging 
as 
war 
: 
configure 
build.groovy 
//... 
apply 
plugin: 
'war' 
war 
{ 
baseName 
= 
'myapp' 
version 
= 
'0.5.0' 
} 
//.... 
configurations 
{ 
providedRuntime 
} 
dependencies 
{ 
compile("org.springframework.boot:spring-­‐boot-­‐starter-­‐web") 
providedRuntime("org.springframework.boot:spring-­‐boot-­‐starter-­‐tomcat") 
// 
... 
} 
$ 
gradle 
war
Q/A 
25
Thank 
you. 
26 
Blog: 
http://www.intelligrape.com/blog/author/bhagwat 
LikedIn: 
http://www.linkedin.com/in/bhagwatkumar 
Twitter: 
http://twitter.com/bhagwatkumar 
Mail 
: 
bhagwat@intelligrape.com
References 
Samples 
: 
https://github.com/bhagwat/spring-­‐boot-­‐samples 
http://docs.spring.io/spring-­‐boot/docs/current-­‐SNAPSHOT/reference/htmlsingle 
http://docs.spring.io/spring-­‐boot/docs/current-­‐SNAPSHOT/reference/htmlsingle/#getting-­‐ 
started-­‐gvm-­‐cli-­‐installation 
https://github.com/spring-­‐projects/spring-­‐boot/tree/master/spring-­‐boot-­‐cli/samples 
http://docs.spring.io/spring-­‐boot/docs/current-­‐SNAPSHOT/reference/htmlsingle/#using-­‐boot-­‐ 
starter-­‐poms 
http://spring.io/guides/gs/accessing-­‐mongodb-­‐data-­‐rest/ 
https://spring.io/guides/gs/accessing-­‐data-­‐mongodb/ 
https://spring.io/guides/gs/accessing-­‐data-­‐jpa/ 
http://www.gradle.org/ 
http://www.slideshare.net/Soddino/developing-­‐an-­‐application-­‐with-­‐spring-­‐boot-­‐34661781 
http://presos.dsyer.com/decks/spring-­‐boot-­‐intro.html 
http://pygments.org/ 
for 
nicely 
formatting 
code 
snippets 
included 
in 
presentation 
27

More Related Content

What's hot

Spring Boot
Spring BootSpring Boot
Spring Boot
Pei-Tang Huang
 
Spring Boot
Spring BootSpring Boot
Spring Boot
HongSeong Jeon
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
Alex Movila
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
Hamid Ghorbani
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
Joshua Long
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
07.pallav
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
Dzmitry Naskou
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring Security
Dzmitry Naskou
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
Jonathan Holloway
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
Rowell Belen
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
Omri Spector
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
Santosh Kumar Kar
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Harshit Choudhary
 
NestJS
NestJSNestJS
NestJS
Wilson Su
 
Spring Boot
Spring BootSpring Boot
Spring Boot
koppenolski
 
Spring boot
Spring bootSpring boot
Spring boot
Pradeep Shanmugam
 

What's hot (20)

Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring Security
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
NestJS
NestJSNestJS
NestJS
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot
Spring bootSpring boot
Spring boot
 

Viewers also liked

That old Spring magic has me in its SpEL
That old Spring magic has me in its SpELThat old Spring magic has me in its SpEL
That old Spring magic has me in its SpEL
Craig Walls
 
Modular Java - OSGi
Modular Java - OSGiModular Java - OSGi
Modular Java - OSGi
Craig Walls
 
Shootout! template engines on the jvm
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvm
NLJUG
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with Spring
Joshua Long
 
Boot It Up
Boot It UpBoot It Up
Boot It Up
Joshua Long
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Abdelhakim Bachar
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
Roman PichlĂ­k
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
IndicThreads
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
Sam Brannen
 
Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
Craig Walls
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
zeeshanhanif
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring Boot
Joshua Long
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVC
digitalsonic
 
Presentation Spring
Presentation SpringPresentation Spring
Presentation Spring
Nathaniel Richand
 
Shootout! Template engines for the JVM
Shootout! Template engines for the JVMShootout! Template engines for the JVM
Shootout! Template engines for the JVM
Jeroen Reijn
 

Viewers also liked (16)

That old Spring magic has me in its SpEL
That old Spring magic has me in its SpELThat old Spring magic has me in its SpEL
That old Spring magic has me in its SpEL
 
Modular Java - OSGi
Modular Java - OSGiModular Java - OSGi
Modular Java - OSGi
 
Shootout! template engines on the jvm
Shootout! template engines on the jvmShootout! template engines on the jvm
Shootout! template engines on the jvm
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with Spring
 
Boot It Up
Boot It UpBoot It Up
Boot It Up
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1Spring Framework 4.0 to 4.1
Spring Framework 4.0 to 4.1
 
Spring Mvc Rest
Spring Mvc RestSpring Mvc Rest
Spring Mvc Rest
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Microservices with Spring Boot
Microservices with Spring BootMicroservices with Spring Boot
Microservices with Spring Boot
 
RESTful Web Services with Spring MVC
RESTful Web Services with Spring MVCRESTful Web Services with Spring MVC
RESTful Web Services with Spring MVC
 
Presentation Spring
Presentation SpringPresentation Spring
Presentation Spring
 
Shootout! Template engines for the JVM
Shootout! Template engines for the JVMShootout! Template engines for the JVM
Shootout! Template engines for the JVM
 

Similar to Spring boot

Grails Spring Boot
Grails Spring BootGrails Spring Boot
Grails Spring Boot
TO THE NEW | Technology
 
Spring boot wednesday
Spring boot wednesdaySpring boot wednesday
Spring boot wednesday
Vinay Prajapati
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
Kevin He
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
Jeevesh Pandey
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
Pagepro
 
Eclipse Buildship DemoCamp Hamburg (June 2015) with additional screenshots
Eclipse Buildship DemoCamp Hamburg (June 2015)  with additional screenshotsEclipse Buildship DemoCamp Hamburg (June 2015)  with additional screenshots
Eclipse Buildship DemoCamp Hamburg (June 2015) with additional screenshots
simonscholz
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
🎤 Hanno Embregts 🎸
 
JVM Web Frameworks Exploration
JVM Web Frameworks ExplorationJVM Web Frameworks Exploration
JVM Web Frameworks Exploration
Kevin H.A. Tan
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
Bhagwat Kumar
 
Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)
Jared Burrows
 
cadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSE
cadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSEcadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSE
cadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSE
CHARANKUMARREDDYBOJJ
 
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)
Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)
🎤 Hanno Embregts 🎸
 
Spring boot 3g
Spring boot 3gSpring boot 3g
Spring boot 3g
vasya10
 
Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1
Vasil Remeniuk
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
NodeXperts
 
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
🎤 Hanno Embregts 🎸
 
Pre-render Blazor WebAssembly on static web hosting at publishing time
Pre-render Blazor WebAssembly on static web hosting at publishing timePre-render Blazor WebAssembly on static web hosting at publishing time
Pre-render Blazor WebAssembly on static web hosting at publishing time
Jun-ichi Sakamoto
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
Alkacon Software GmbH & Co. KG
 
Eclipse Buildship JUG Hamburg
Eclipse Buildship JUG HamburgEclipse Buildship JUG Hamburg
Eclipse Buildship JUG Hamburg
simonscholz
 
Grails
GrailsGrails
Grails
Vijay Shukla
 

Similar to Spring boot (20)

Grails Spring Boot
Grails Spring BootGrails Spring Boot
Grails Spring Boot
 
Spring boot wednesday
Spring boot wednesdaySpring boot wednesday
Spring boot wednesday
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Eclipse Buildship DemoCamp Hamburg (June 2015) with additional screenshots
Eclipse Buildship DemoCamp Hamburg (June 2015)  with additional screenshotsEclipse Buildship DemoCamp Hamburg (June 2015)  with additional screenshots
Eclipse Buildship DemoCamp Hamburg (June 2015) with additional screenshots
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
 
JVM Web Frameworks Exploration
JVM Web Frameworks ExplorationJVM Web Frameworks Exploration
JVM Web Frameworks Exploration
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)
 
cadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSE
cadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSEcadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSE
cadec-2029-SPRING SPRING BOOT LEARNIGN PURPOSE
 
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)
Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)Building a Spring Boot Application - Ask the Audience!  (from JavaLand 2017)
Building a Spring Boot Application - Ask the Audience! (from JavaLand 2017)
 
Spring boot 3g
Spring boot 3gSpring boot 3g
Spring boot 3g
 
Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1Scala laboratory. Globus. iteration #1
Scala laboratory. Globus. iteration #1
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
 
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
Building a Spring Boot Application - Ask the Audience! (from JVMCon 2018)
 
Pre-render Blazor WebAssembly on static web hosting at publishing time
Pre-render Blazor WebAssembly on static web hosting at publishing timePre-render Blazor WebAssembly on static web hosting at publishing time
Pre-render Blazor WebAssembly on static web hosting at publishing time
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
 
Eclipse Buildship JUG Hamburg
Eclipse Buildship JUG HamburgEclipse Buildship JUG Hamburg
Eclipse Buildship JUG Hamburg
 
Grails
GrailsGrails
Grails
 

Recently uploaded

220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt
Kalna College
 
Principles of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptxPrinciples of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptx
ibtesaam huma
 
The basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptxThe basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptx
heathfieldcps1
 
Final ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdfFinal ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdf
Zuzana MĂŠszĂĄrosovĂĄ
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
Dr Vijay Vishwakarma
 
The Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptx
The Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptxThe Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptx
The Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptx
OH TEIK BIN
 
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptxUNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
hemaxiparmar
 
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Celine George
 
Righteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdfRighteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdf
Zuzana MĂŠszĂĄrosovĂĄ
 
Front Desk Management in the Odoo 17 ERP
Front Desk  Management in the Odoo 17 ERPFront Desk  Management in the Odoo 17 ERP
Front Desk Management in the Odoo 17 ERP
Celine George
 
Capitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptxCapitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptx
CapitolTechU
 
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdfARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
DharmarajPawar
 
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
PECB
 
hISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdf
hISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdfhISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdf
hISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdf
zuzanka
 
Debts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptxDebts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptx
AncyTEnglish
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
Celine George
 
How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17
Celine George
 
debts of gratitude 2 detailed meaning and certificate of appreciation.pptx
debts of gratitude 2 detailed meaning and certificate of appreciation.pptxdebts of gratitude 2 detailed meaning and certificate of appreciation.pptx
debts of gratitude 2 detailed meaning and certificate of appreciation.pptx
AncyTEnglish
 
Book Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docxBook Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docx
drtech3715
 
NationalLearningCamp-2024-Orientation-for-RO-SDO.pptx
NationalLearningCamp-2024-Orientation-for-RO-SDO.pptxNationalLearningCamp-2024-Orientation-for-RO-SDO.pptx
NationalLearningCamp-2024-Orientation-for-RO-SDO.pptx
CelestineMiranda
 

Recently uploaded (20)

220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt220711130045_PRIYA_DAS_M.S___Access__ppt
220711130045_PRIYA_DAS_M.S___Access__ppt
 
Principles of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptxPrinciples of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptx
 
The basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptxThe basics of sentences session 9pptx.pptx
The basics of sentences session 9pptx.pptx
 
Final ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdfFinal ebook Keeping the Memory @live.pdf
Final ebook Keeping the Memory @live.pdf
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
 
The Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptx
The Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptxThe Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptx
The Value of Time ~ A Story to Ponder On (Eng. & Chi.).pptx
 
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptxUNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
UNIT 5 - PATIENT SAFETY & CLINICAL RISK.pptx
 
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17
 
Righteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdfRighteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdf
 
Front Desk Management in the Odoo 17 ERP
Front Desk  Management in the Odoo 17 ERPFront Desk  Management in the Odoo 17 ERP
Front Desk Management in the Odoo 17 ERP
 
Capitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptxCapitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptx
 
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdfARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
 
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894
 
hISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdf
hISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdfhISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdf
hISTORY OF THE jEWISH COMMUNITY IN ROMANIA.pdf
 
Debts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptxDebts of gratitude 4meanings announcement format.pptx
Debts of gratitude 4meanings announcement format.pptx
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
 
How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17
 
debts of gratitude 2 detailed meaning and certificate of appreciation.pptx
debts of gratitude 2 detailed meaning and certificate of appreciation.pptxdebts of gratitude 2 detailed meaning and certificate of appreciation.pptx
debts of gratitude 2 detailed meaning and certificate of appreciation.pptx
 
Book Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docxBook Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docx
 
NationalLearningCamp-2024-Orientation-for-RO-SDO.pptx
NationalLearningCamp-2024-Orientation-for-RO-SDO.pptxNationalLearningCamp-2024-Orientation-for-RO-SDO.pptx
NationalLearningCamp-2024-Orientation-for-RO-SDO.pptx
 

Spring boot

  • 1. Spring Boot By Bhagwat Kumar
  • 2. Agenda • What and Why? • Key features of Spring boot • Prototyping using CLI. • Gradle primer • Managing profiles aka environment in grails • Using Spring data libraries e.g. MongoDB • Using GORM • Presentation layer • Using GSP 2
  • 3. What and why? • Its not a replacement for Spring framework but it presents a small surface area for users to approach and extract value from the rest of Spring. • Spring-­‐boot provides a quick way to create a Spring based application from dependency management to convention over configuration. • Grails 3.0 will be based on Spring Boot. image source : http://spring.io/blog/2013/08/06/spring-­‐boot-­‐simplifying-­‐spring-­‐for-­‐everyone 3
  • 4. Key Features • Stand-­‐alone Spring applications • No code generation/ No XML Config • Automatic configuration by creating sensible defaults • Starter dependencies • Structure your code as you like • Supports Gradle and Maven • Common non-­‐functional requirements for a "real" application – embedded servers, – security, metrics, health checks – externalised configuration
  • 5. Rapid Prototyping : Spring CLI • Quickest way to get a spring app off the ground • Allows you to run groovy scripts without much boilerplate code • Not recommended for production Install using GVM $ gvm install springboot Running groovy scripts $ spring run app.groovy $ spring run --watch app.groovy $ spring test tests.groovy
  • 6. A quick web application using spring boot app.groovy @Controller class Example { @RequestMapping("/") @ResponseBody public String helloWorld() { "Hello Spring boot audience!!!" } } $ spring run app.groovy
  • 7. What Just happened? // import org.springframework.web.bind.annotation.Controller // other imports ... // @Grab("org.springframework.boot:spring-­‐boot-­‐web-­‐starter:0.5.0") // @EnableAutoConfiguration @Controller class Example { @RequestMapping("/") @ResponseBody public String hello() { return "Hello World!"; } // public static void main(String[] args) { // SpringApplication.run(Example.class, args); // } }
  • 8. Starter POMs • One-­‐stop-­‐shop for all the Spring and related technology • A set of convenient dependency descriptors • Contain a lot of the dependencies that you need to get a project up and running quickly • All starters follow a similar naming pattern; – spring-­‐boot-­‐starter-­‐* • Examples – spring-­‐boot-­‐starter-­‐web – spring-­‐boot-­‐starter-­‐data-­‐rest – spring-­‐boot-­‐starter-­‐security – spring-­‐boot-­‐starter-­‐amqp – spring-­‐boot-­‐starter-­‐data-­‐jpa – spring-­‐boot-­‐starter-­‐data-­‐elasticsearch – spring-­‐boot-­‐starter-­‐data-­‐mongodb – spring-­‐boot-­‐starter-­‐actuator
  • 9. Demo : Starter POMs @Grab('spring-­‐boot-­‐starter-­‐security') @Grab('spring-­‐boot-­‐starter-­‐actuator') @Controller class Example { @RequestMapping("/") @ResponseBody public String helloWorld() { return "Hello Audience!!!" } } //security.user.name : default 'user' //security.user.password : see log for auto generated password //actuator endpoints: /beans, /health, /mappings, /metrics etc.
  • 11. Lets go beyond prototyping : Gradle Image source : http://www.drdobbs.com/jvm/why-­‐build-­‐your-­‐java-­‐projects-­‐with-­‐gradle/240168608
  • 12. build.gradle task hello << { println "Hello !!!!" } task greet <<{ println "Welocome Mr. Kumar" } task intro(dependsOn: hello) << { println "I'm Gradle" } hello << { println "Hello extended!!!!" } greet.dependsOn hello, intro // gradle tasks :list all the available tasks // gradle intro :executes intro task // gradle -­‐q greet :bare build output // gradle -­‐-­‐daemon hello :subsequent execution will be fast
  • 13. build.gradle : using plugin and adding dependencies apply plugin: "groovy" //look for sources in src/main/groovy folder //inherits java plugin: src/main/java folder // tasks compileJava, compileGroovy, build, clean sourceCompatibility = 1.6 repositories { mavenCentral() } dependencies { compile 'org.codehaus.groovy:groovy-­‐all:2.3.6' compile "org.apache.commons:commons-­‐lang3:3.0.1" testCompile "junit:unit:4.+" }
  • 14. build.gradle: for Spring boot app with hot reloading apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'spring-­‐boot' buildscript { repositories { mavenCentral()} dependencies { classpath("org.springframework.boot:spring-­‐boot-­‐gradle-­‐plugin:1.1.8.RELEASE") classpath 'org.springframework:springloaded:1.2.0.RELEASE' } } idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } } repositories { mavenCentral() } dependencies { compile 'org.codehaus.groovy:groovy-­‐all' compile 'org.springframework.boot:spring-­‐boot-­‐starter-­‐web' }
  • 15. Environment and Profile aka Grails config • Put application.properties/application.yml somewhere in classpath • Easy one: src/main/resources folder 15 application.yml app: name: Springboot+Config+Yml+Demo version: 1.0.0 server: port: 8080 settings: counter: 1 -­‐-­‐-­‐ spring: profiles: development server: port: 9001 application.properties app.name=Springboot+Config+Demo app.version=1.0.0 server.port=8080 settings.coutner=1 application-­‐development.properties app.name=Springboot+Config+Demo app.version=1.0.0 server.port=8080
  • 16. Binding properties 16 Using ConfigurationProperties annotation import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.stereotype.Component @Component @ConfigurationProperties(prefix = "app") class AppInfo { String name String version } Using Value annotation import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component @Component class AppConfig { @Value('${app.name}') String appName @Value('${server.port}') Integer port }
  • 17. Examples 17 OS env variable export SPRING_PROFILES_ACTIVE=development export SERVER_PORT=8090 gradle bootRun java -­‐jar build/libs/demo-­‐1.0.0.jar with a -­‐D argument (remember to put it before the main class or jar archive) java -­‐jar -­‐Dspring.profiles.active=development build/libs/dem-­‐1.0.0.jar java -­‐jar -­‐Dserver.port=8090 build./libs/demo-­‐1.0.0.jar
  • 18. Using Spring data • Add dependency compile 'org.springframework.boot:spring-­‐boot-­‐starter-­‐data-­‐mongodb' • Configure database URL spring.data.mongodb.uri=mongodb://localhost/springtestdev • Add entity class import org.springframework.data.annotation.Id; class • Add Person{@Id String id, String name} repository interface import org.springframework.data.mongodb.repository.MongoRepository public interface PersonRepository extends • Autowire and use like charm MongoRepository<Person, String> {} @Autowired PersonRepository personRepository personRepository.save(new Person(name:'Spring Boot')) personRepository.findAll() personRepository.count()
  • 19. Next level persistence with GORM • Add dependencies to use GORM-­‐Hibernate • For GORM MongoDB use the following dependencies compile 'org.grails:gorm-­‐mongodb-­‐spring-­‐boot:1.1.0.RELEASE' • Add entity with @grails.persistence.entity 19 compile 'org.springframework.boot:spring-­‐boot-­‐starter-­‐data-­‐jpa' compile 'org.grails:gorm-­‐hibernate4-­‐spring-­‐boot:1.1.0.RELEASE' runtime 'com.h2database:h2' //for h2 database import grails.persistence.Entity @Entity class Person { String name; Integer age static constraints = { name blank: false age min: 15 } } Further reading https://github.com/grails/grails-­‐data-­‐mapping
  • 20. Server side view template libraries • JSP/JSTL • Thymeleaf • Freemarker • Velocity • Tiles • GSP • Groovy Template Engine 20
  • 21. • Very limited existing tags available • https://github.com/grails/grails-­‐boot/issues/3 • Add dependency • Put GSP templates in resources/templates folder GSP 21 compile "org.grails:grails-­‐gsp-­‐spring-­‐boot:1.0.0.RC1" compile "org.grails:grails-­‐web:2.4.0.M2"
  • 22. GSP continued... • Sample request handler 22 @RequestMapping("/show/{id}") public ModelAndView show(@PathVariable Long id) { Person person = Person.read(id) if (person) { //render(view:"/person/show", model:[personInstance:personInstance]) new ModelAndView("/person/show", [personInstance: Person.get(id)]) } else { log.info "No entity fount for id : " + id //redirect(controller:"person", action:"list") new ModelAndView("redirect:/person/list") } }
  • 23. Grails Taglib 23 @grails.gsp.TagLib @org.springframework.stereotype.Component class ApplicationTagLib { static namespace = "app" def paginate = { attrs -­‐> String action = attrs.action Integer total = attrs.total Integer currentPage = attrs.currentPage ?: 1 Integer pages = (total / 10) + 1 out << render(template: "/shared/pagination", model: [action: action, total: total, currentPage: currentPage, pages: pages] ) } } <app:paginate total="${personInstanceCount ?: 0}" currentPage="${currentPage}" action="/person/list"/>
  • 24. Packaging executable jar and war files 24 Packaging as jar with embedded tomcat $ gradle build $ java -­‐jar build/libs/mymodule-­‐0.0.1-­‐SNAPSHOT.jar Packaging as war : configure build.groovy //... apply plugin: 'war' war { baseName = 'myapp' version = '0.5.0' } //.... configurations { providedRuntime } dependencies { compile("org.springframework.boot:spring-­‐boot-­‐starter-­‐web") providedRuntime("org.springframework.boot:spring-­‐boot-­‐starter-­‐tomcat") // ... } $ gradle war
  • 26. Thank you. 26 Blog: http://www.intelligrape.com/blog/author/bhagwat LikedIn: http://www.linkedin.com/in/bhagwatkumar Twitter: http://twitter.com/bhagwatkumar Mail : bhagwat@intelligrape.com
  • 27. References Samples : https://github.com/bhagwat/spring-­‐boot-­‐samples http://docs.spring.io/spring-­‐boot/docs/current-­‐SNAPSHOT/reference/htmlsingle http://docs.spring.io/spring-­‐boot/docs/current-­‐SNAPSHOT/reference/htmlsingle/#getting-­‐ started-­‐gvm-­‐cli-­‐installation https://github.com/spring-­‐projects/spring-­‐boot/tree/master/spring-­‐boot-­‐cli/samples http://docs.spring.io/spring-­‐boot/docs/current-­‐SNAPSHOT/reference/htmlsingle/#using-­‐boot-­‐ starter-­‐poms http://spring.io/guides/gs/accessing-­‐mongodb-­‐data-­‐rest/ https://spring.io/guides/gs/accessing-­‐data-­‐mongodb/ https://spring.io/guides/gs/accessing-­‐data-­‐jpa/ http://www.gradle.org/ http://www.slideshare.net/Soddino/developing-­‐an-­‐application-­‐with-­‐spring-­‐boot-­‐34661781 http://presos.dsyer.com/decks/spring-­‐boot-­‐intro.html http://pygments.org/ for nicely formatting code snippets included in presentation 27