SlideShare una empresa de Scribd logo
1 de 25
Spring Boot
By Bhagwat Kumar
AGENDA
1. What and why?
2. Key features ofSpring boot
3. Prototyping usingCLI
4. Gradle primer
5. Managing profiles aka environment in grails
6. Using Spring data libraries e.g. MongoDB
7. UsingGORM
8. Presentation layer
9. UsingGSP
• Its not a replacement for Spring framework but it presents a small
surface area for usersto 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.0will be based on Spring Boot
WHAT & WHY?
• Stand-alone Springapplications
• No code generation/ No XML Config
• Automatic configuration by creating sensible defaults
• Starterdependencies
• Structure your code as you like
• Supports Gradle andMaven
• Common non-functional requirements for a "real" application
- embedded servers,
- security, metrics, healthchecks
- externalized configuration
KEY FEATURES
• Quickest way to get a spring app off the ground
• Allows you to run groovy scripts without much boilerplate code
• Not recommended forproduction
RAPID PROTOTYPING : SPRING CLI
@Controller
classExample{
@RequestMapping("/")
@ResponseBody
public StringhelloWorld(){
"Hello Spring bootaudience!!!"
}
}
GETTING STARTED REALLY QUICKLY
// importorg.springframework.web.bind.annotation.Controller
// otherimports...
//@Grab("org.springframework.boot:spring-boot-web-starter:0.5.0")
//@EnableAutoConfiguration
@Controller
classExample{
@RequestMapping("/")
@ResponseBody
publicStringhello(){
return"HelloWorld!";
}
// public static void main(String[]args){
// SpringApplication.run(Example.class,args);
// }
}
WHAT JUST HAPPENED?
• 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 runningquickly
• All starters follow a similarnaming 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
STARTER POMs
DEMO: STARTER POMs
LETS GO BEYOND PROTOTYPING : GRADLE
task hello <<{
println "Hello!!!!"
}
task greet<<{
println "Welocome Mr.Kumar"
}
task intro(dependsOn: hello)<<{
println "I'mGradle"
}
hello <<{println "Hello extended!!!!" }
greet.dependsOn hello,intro
// gradletasks
// gradleintro
:listall the available tasks
:executes introtask
// gradle -q greet :bare build output
// gradle --daemon hello:subsequent execution wil be fast
BUILD.GRADLE
apply plugin:"groovy"
//look for sources in src/main/groovyfolder
//inherits java plugin: src/main/javafolder
// 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: USING PLUGIN AND
ADDING DEPENDENCIES
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'
}
BUILD.GRADLE: FOR SPRING BOOT APP
WITH HOT RELOADING
• Put application.properties/application.yml somewhere in classpath
• Easy one: src/main/resourcesfolder
ENVIRONMENT AND PROFILE AKA GRAILS
CONFIG
Using ConfigurationProperties annotation
import org.springframework.boot.context.properties.ConfigurationProperties
importorg.springframework.stereotype.Component
@Component
@ConfigurationProperties(prefix="app")
class AppInfo {
String name
Stringversion
}
Using Valueannotation
importorg.springframework.beans.factory.annotation.Value
importorg.springframework.stereotype.Component
@Component
classAppConfig{
@Value('${app.name}')
StringappName
@Value('${server.port}')
Integerport
}
BINDING PROPERTIES
OS envvariable
export SPRING_PROFILES_ACTIVE=development
export SERVER_PORT=8090
gradle bootRun
java -jarbuild/libs/demo-1.0.0.jar
with a -D argument (remember to put it before the main class or jararchive)
java -jar -Dspring.profiles.active=development build/libs/dem-1.0.0.jar
java -jar -Dserver.port=8090build./libs/demo-1.0.0.jar
EXAMPLES
• Add dependency
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
• Configure database URL
spring.data.mongodb.uri=mongodb://localhost/springtestdev
• Add entityclass
importorg.springframework.data.annotation.Id;
classPerson{@IdStringid, Stringname}
• Add repositoryinterface
importorg.springframework.data.mongodb.repository.MongoRepository
public interface PersonRepositoryextendsMongoRepository<Person, String> {}
• Autowire and use like charm
@AutowiredPersonRepository personRepository
personRepository.save(new Person(name:'SpringBoot'))
personRepository.findAll()
personRepository.count()
USING SPRING DATA
• Add dependencies to use GORM-Hibernate
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 h2database
• Add entity with@grails.persistence.entity
importgrails.persistence.Entity
@Entity
class Person{
Stringname;
Integerage
static constraints ={
name blank:false
age min:15
}
}
• For GORM MongoDB use the following dependencies
compile 'org.grails:gorm-mongodb-spring-boot:1.1.0.RELEASE'
NEXT LEVEL PERSISTENCE WITH GORM
• JSP/JSTL
• Thymeleaf
• Freemarker
• Velocity
• Tiles
• GSP
• Groovy TemplateEngine
SERVER SIDE VIEW TEMPLATE LIBRARIES
• Very limited existing tags available
https://github.com/grails/grails-boot/issues/3
• Add dependency
compile "org.grails:grails-gsp-spring-boot:1.0.0.RC1"
compile "org.grails:grails-web:2.4.0.M2"
• Put gsptemplates in resources/templates folder
GSP
• Sample requesthandler
@RequestMapping("/show/{id}")
public ModelAndView show(@PathVariableLong id){
Person person =Person.read(id)
if(person) {
new ModelAndView("/person/show",[personInstance:Person.get(id)])
}else{
log.info "No entity fount for id:"+id
newModelAndView("redirect:/person/list")
}
}
GSP CONTINUED
@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"/>
GRAILS TAGLIB
Packaging as jar with embedded tomcat
$gradle build
$java -jarbuild/libs/mymodule-0.0.1-SNAPSHOT.jar
Packaging as war :configurebuild.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
PACKAGING EXECUTABLE JAR AND WAR
FILES
Contact us
Our Office
Client
Location
Click Here To Know More!
Have more queries on Grails?
Talk to our GRAILS experts
Now!
Talk To Our Experts
Here's how the world's
biggest Grails team is
building enterprise
applications on Grails!

Más contenido relacionado

La actualidad más candente

Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
Gunith Devasurendra
 

La actualidad más candente (20)

Spring Boot & Actuators
Spring Boot & ActuatorsSpring Boot & Actuators
Spring Boot & Actuators
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring 2.0 技術手冊第一章 - 認識 Spring
Spring 2.0 技術手冊第一章 - 認識 SpringSpring 2.0 技術手冊第一章 - 認識 Spring
Spring 2.0 技術手冊第一章 - 認識 Spring
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Xke spring boot
Xke spring bootXke spring boot
Xke spring boot
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
Maven 3 Overview
Maven 3  OverviewMaven 3  Overview
Maven 3 Overview
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Spring core module
Spring core moduleSpring core module
Spring core module
 
深入淺出 Web 容器 - Tomcat 原始碼分析
深入淺出 Web 容器  - Tomcat 原始碼分析深入淺出 Web 容器  - Tomcat 原始碼分析
深入淺出 Web 容器 - Tomcat 原始碼分析
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 

Destacado

Schema 25.09.2010 rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001
Schema 25.09.2010   rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001Schema 25.09.2010   rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001
Schema 25.09.2010 rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001
OffshoreGroup™
 
C:\Fakepath\Nucleotide A H1 N1
C:\Fakepath\Nucleotide A H1 N1C:\Fakepath\Nucleotide A H1 N1
C:\Fakepath\Nucleotide A H1 N1
picardo123
 
Open Day Presentation
Open Day Presentation Open Day Presentation
Open Day Presentation
sallyross
 
Investor communications highlights
Investor communications highlightsInvestor communications highlights
Investor communications highlights
Peter Gallagher
 
Behavioural Marketing…or how to get your customers to love you
Behavioural Marketing…or how to get your customers to love youBehavioural Marketing…or how to get your customers to love you
Behavioural Marketing…or how to get your customers to love you
John Watton
 
Michacle angelo
Michacle angeloMichacle angelo
Michacle angelo
sathma
 
Open day presentation
Open day presentation Open day presentation
Open day presentation
sallyross
 
FUKUYAMA BASE WORKSHOP Vol14 Theme
FUKUYAMA BASE WORKSHOP Vol14 ThemeFUKUYAMA BASE WORKSHOP Vol14 Theme
FUKUYAMA BASE WORKSHOP Vol14 Theme
noteproject
 

Destacado (20)

Use groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projectsUse groovy & grails in your spring boot projects
Use groovy & grails in your spring boot projects
 
GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3
GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3
GGX 2014 Lari Hotari Modular Monoliths with Spring Boot and Grails 3
 
O Spring está morto! Viva o Spring!
O Spring está morto! Viva o Spring!O Spring está morto! Viva o Spring!
O Spring está morto! Viva o Spring!
 
Spring boot
Spring bootSpring boot
Spring boot
 
Schema 25.09.2010 rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001
Schema 25.09.2010   rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001Schema 25.09.2010   rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001
Schema 25.09.2010 rigger o-3.2, borr- och brunntekniker vg2 - 16 v - r0001
 
Behavioural Marketing & how to get your customers to love you
Behavioural Marketing & how to get your customers to love youBehavioural Marketing & how to get your customers to love you
Behavioural Marketing & how to get your customers to love you
 
Behavioural Marketing…or how to get your customers to love you
Behavioural Marketing…or how to get your customers to love youBehavioural Marketing…or how to get your customers to love you
Behavioural Marketing…or how to get your customers to love you
 
C:\Fakepath\Nucleotide A H1 N1
C:\Fakepath\Nucleotide A H1 N1C:\Fakepath\Nucleotide A H1 N1
C:\Fakepath\Nucleotide A H1 N1
 
Markatalyst Overview
Markatalyst OverviewMarkatalyst Overview
Markatalyst Overview
 
Jaarovergang in itslearning
Jaarovergang in itslearningJaarovergang in itslearning
Jaarovergang in itslearning
 
Open Day Presentation
Open Day Presentation Open Day Presentation
Open Day Presentation
 
Investor communications highlights
Investor communications highlightsInvestor communications highlights
Investor communications highlights
 
Behavioural Marketing…or how to get your customers to love you
Behavioural Marketing…or how to get your customers to love youBehavioural Marketing…or how to get your customers to love you
Behavioural Marketing…or how to get your customers to love you
 
Portfolio
PortfolioPortfolio
Portfolio
 
Michacle angelo
Michacle angeloMichacle angelo
Michacle angelo
 
Getting groovier-with-vertx
Getting groovier-with-vertxGetting groovier-with-vertx
Getting groovier-with-vertx
 
Sergio Santos Portfolio
Sergio Santos PortfolioSergio Santos Portfolio
Sergio Santos Portfolio
 
Open day presentation
Open day presentation Open day presentation
Open day presentation
 
FUKUYAMA BASE WORKSHOP Vol14 Theme
FUKUYAMA BASE WORKSHOP Vol14 ThemeFUKUYAMA BASE WORKSHOP Vol14 Theme
FUKUYAMA BASE WORKSHOP Vol14 Theme
 
Practicing Agile in Offshore Environment
Practicing Agile in Offshore EnvironmentPracticing Agile in Offshore Environment
Practicing Agile in Offshore Environment
 

Similar a Grails Spring Boot

Similar a Grails Spring Boot (20)

Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
What's new in Gradle 4.0
What's new in Gradle 4.0What's new in Gradle 4.0
What's new in Gradle 4.0
 
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
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 
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)
 
Spring boot wednesday
Spring boot wednesdaySpring boot wednesday
Spring boot wednesday
 
ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!
 
Eclipse Buildship JUG Hamburg
Eclipse Buildship JUG HamburgEclipse Buildship JUG Hamburg
Eclipse Buildship JUG Hamburg
 
Grails
GrailsGrails
Grails
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Slim3 quick start
Slim3 quick startSlim3 quick start
Slim3 quick start
 
JVM Web Frameworks Exploration
JVM Web Frameworks ExplorationJVM Web Frameworks Exploration
JVM Web Frameworks Exploration
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for android
 
7 maven vsgradle
7 maven vsgradle7 maven vsgradle
7 maven vsgradle
 
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
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Grunt & Front-end Workflow
Grunt & Front-end WorkflowGrunt & Front-end Workflow
Grunt & Front-end Workflow
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 

Más de TO THE NEW | Technology

10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:
TO THE NEW | Technology
 
12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C
TO THE NEW | Technology
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
TO THE NEW | Technology
 
MongoDb and NoSQL
MongoDb and NoSQLMongoDb and NoSQL
MongoDb and NoSQL
TO THE NEW | Technology
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
TO THE NEW | Technology
 
BigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchBigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearch
TO THE NEW | Technology
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
TO THE NEW | Technology
 
Introduction to Kanban
Introduction to KanbanIntroduction to Kanban
Introduction to Kanban
TO THE NEW | Technology
 

Más de TO THE NEW | Technology (20)

10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!10 Best Node.js Practices you Need to Know!
10 Best Node.js Practices you Need to Know!
 
10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:10 Pragmatic UX techniques for building smarter products:
10 Pragmatic UX techniques for building smarter products:
 
12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C12 Key points which make Swift more effective than Objective C
12 Key points which make Swift more effective than Objective C
 
Gulp - The Streaming Build System
Gulp - The Streaming Build SystemGulp - The Streaming Build System
Gulp - The Streaming Build System
 
AWS Elastic Beanstalk
AWS Elastic BeanstalkAWS Elastic Beanstalk
AWS Elastic Beanstalk
 
Content migration to AEM
Content migration to AEMContent migration to AEM
Content migration to AEM
 
AWS CodeDeploy
AWS CodeDeployAWS CodeDeploy
AWS CodeDeploy
 
Big Data Expertise
Big Data ExpertiseBig Data Expertise
Big Data Expertise
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScript
 
Object Oriented JavaScript - II
Object Oriented JavaScript - IIObject Oriented JavaScript - II
Object Oriented JavaScript - II
 
MongoDb and NoSQL
MongoDb and NoSQLMongoDb and NoSQL
MongoDb and NoSQL
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
Cloud Formation
Cloud FormationCloud Formation
Cloud Formation
 
BigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearchBigData Search Simplified with ElasticSearch
BigData Search Simplified with ElasticSearch
 
JULY IN GRAILS
JULY IN GRAILSJULY IN GRAILS
JULY IN GRAILS
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Introduction to Kanban
Introduction to KanbanIntroduction to Kanban
Introduction to Kanban
 
Introduction to Heroku
Introduction to HerokuIntroduction to Heroku
Introduction to Heroku
 
Node JS
Node JSNode JS
Node JS
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Grails Spring Boot

  • 1.
  • 3. AGENDA 1. What and why? 2. Key features ofSpring boot 3. Prototyping usingCLI 4. Gradle primer 5. Managing profiles aka environment in grails 6. Using Spring data libraries e.g. MongoDB 7. UsingGORM 8. Presentation layer 9. UsingGSP
  • 4. • Its not a replacement for Spring framework but it presents a small surface area for usersto 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.0will be based on Spring Boot WHAT & WHY?
  • 5. • Stand-alone Springapplications • No code generation/ No XML Config • Automatic configuration by creating sensible defaults • Starterdependencies • Structure your code as you like • Supports Gradle andMaven • Common non-functional requirements for a "real" application - embedded servers, - security, metrics, healthchecks - externalized configuration KEY FEATURES
  • 6. • Quickest way to get a spring app off the ground • Allows you to run groovy scripts without much boilerplate code • Not recommended forproduction RAPID PROTOTYPING : SPRING CLI
  • 9. • 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 runningquickly • All starters follow a similarnaming 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 STARTER POMs
  • 11. LETS GO BEYOND PROTOTYPING : GRADLE
  • 12. task hello <<{ println "Hello!!!!" } task greet<<{ println "Welocome Mr.Kumar" } task intro(dependsOn: hello)<<{ println "I'mGradle" } hello <<{println "Hello extended!!!!" } greet.dependsOn hello,intro // gradletasks // gradleintro :listall the available tasks :executes introtask // gradle -q greet :bare build output // gradle --daemon hello:subsequent execution wil be fast BUILD.GRADLE
  • 13. apply plugin:"groovy" //look for sources in src/main/groovyfolder //inherits java plugin: src/main/javafolder // 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: USING PLUGIN AND ADDING DEPENDENCIES
  • 14. 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' } BUILD.GRADLE: FOR SPRING BOOT APP WITH HOT RELOADING
  • 15. • Put application.properties/application.yml somewhere in classpath • Easy one: src/main/resourcesfolder ENVIRONMENT AND PROFILE AKA GRAILS CONFIG
  • 16. Using ConfigurationProperties annotation import org.springframework.boot.context.properties.ConfigurationProperties importorg.springframework.stereotype.Component @Component @ConfigurationProperties(prefix="app") class AppInfo { String name Stringversion } Using Valueannotation importorg.springframework.beans.factory.annotation.Value importorg.springframework.stereotype.Component @Component classAppConfig{ @Value('${app.name}') StringappName @Value('${server.port}') Integerport } BINDING PROPERTIES
  • 17. OS envvariable export SPRING_PROFILES_ACTIVE=development export SERVER_PORT=8090 gradle bootRun java -jarbuild/libs/demo-1.0.0.jar with a -D argument (remember to put it before the main class or jararchive) java -jar -Dspring.profiles.active=development build/libs/dem-1.0.0.jar java -jar -Dserver.port=8090build./libs/demo-1.0.0.jar EXAMPLES
  • 18. • Add dependency compile 'org.springframework.boot:spring-boot-starter-data-mongodb' • Configure database URL spring.data.mongodb.uri=mongodb://localhost/springtestdev • Add entityclass importorg.springframework.data.annotation.Id; classPerson{@IdStringid, Stringname} • Add repositoryinterface importorg.springframework.data.mongodb.repository.MongoRepository public interface PersonRepositoryextendsMongoRepository<Person, String> {} • Autowire and use like charm @AutowiredPersonRepository personRepository personRepository.save(new Person(name:'SpringBoot')) personRepository.findAll() personRepository.count() USING SPRING DATA
  • 19. • Add dependencies to use GORM-Hibernate 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 h2database • Add entity with@grails.persistence.entity importgrails.persistence.Entity @Entity class Person{ Stringname; Integerage static constraints ={ name blank:false age min:15 } } • For GORM MongoDB use the following dependencies compile 'org.grails:gorm-mongodb-spring-boot:1.1.0.RELEASE' NEXT LEVEL PERSISTENCE WITH GORM
  • 20. • JSP/JSTL • Thymeleaf • Freemarker • Velocity • Tiles • GSP • Groovy TemplateEngine SERVER SIDE VIEW TEMPLATE LIBRARIES
  • 21. • Very limited existing tags available https://github.com/grails/grails-boot/issues/3 • Add dependency compile "org.grails:grails-gsp-spring-boot:1.0.0.RC1" compile "org.grails:grails-web:2.4.0.M2" • Put gsptemplates in resources/templates folder GSP
  • 22. • Sample requesthandler @RequestMapping("/show/{id}") public ModelAndView show(@PathVariableLong id){ Person person =Person.read(id) if(person) { new ModelAndView("/person/show",[personInstance:Person.get(id)]) }else{ log.info "No entity fount for id:"+id newModelAndView("redirect:/person/list") } } GSP CONTINUED
  • 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"/> GRAILS TAGLIB
  • 24. Packaging as jar with embedded tomcat $gradle build $java -jarbuild/libs/mymodule-0.0.1-SNAPSHOT.jar Packaging as war :configurebuild.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 PACKAGING EXECUTABLE JAR AND WAR FILES
  • 25. Contact us Our Office Client Location Click Here To Know More! Have more queries on Grails? Talk to our GRAILS experts Now! Talk To Our Experts Here's how the world's biggest Grails team is building enterprise applications on Grails!