SlideShare a Scribd company logo
Creating Modular Test Driven SPAs with 
Spring And AngularJS 
By Gunnar Hillert - @ghillert 
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Goals 
• AngularJS Introduction 
• Build and Deployment 
• Integration with Spring 
• Modularization 
• Testing 
• UI Considerations 
2
Me 
• (Java) Web developer since 2005 
• Struts 1+2, Spring MVC, GWT, Flex 
• Spring Integration + XD committer 
• AngularJS since Jan 2014 
• Co-organize 
3
Non-screen activities 
4
AngularJS Introduction 
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Audience - What do you use*? 
• AngularJS 
• Backbone 
• JQuery 
• Are you using any other SPA Framework? Ember.js 
• Spring MVC 
• Spring Boot 
6 
60% 
20% 
80% 
1 user 
80% 
20% 
* Recorded from memory
What are SPAs? 
7 
A single-page application (SPA), also known as single-page 
interface (SPI), is a web application or web site that 
fits on a single web page with the goal of providing a more 
fluid user experience akin to a desktop application. 
Wikipedia
What are SPAs? 
8
JavaScript WTF 
• http://wtfjs.com/ 
9 
parseInt('crap'); // NaN 
parseInt('crap', 16);// 12 
! 
(2 + "3"); // 23 
(2 + +"3"); // 5 
(+""); // 0
Read this 
10
From Backbone to Angular 
• Too many moving parts, choices 
• Boilerplate Code 
• Marionette, Backbone.ModelBinder, Backbone.Relational 
11
Alternatives 
12
AngularJS Basics 
• Model 
• View (Templates) 
• Controller 
• Dependency Injection 
• Expressions 
• Filters 
• Directives 
• Routing 
• Modules 
• See also: AngularJS Concepts 
13
Model 
• Angular is very flexible about your model 
• Ultimately expressed via the $scope 
• $scope = Glue between Controller and View 
• $scope mimics DOM (Hierarchical, one $rootScope) 
14
Model 
• Killer Feature: Data-Binding 
• Model === single-source-of-truth 
• View reflects model changes automatically 
• $watch, $apply 
15
View 
• HTML is your templating Engine 
• Minimize logic as much as possible 
• Consider Custom Directives 
16
¡Hola! 
• Demo 
17 
<div ng-app ng-init="firstName='Eric';lastName='Cartman'"> 
<div> 
First Name: <input type="text" ng-model="firstName"> 
</div> 
<div> 
Last Name: <input type="text" ng-model="lastName"> 
</div> 
<div> 
<b>Complete Name:</b> {{firstName + ' ' + lastName | uppercase}} 
</div> 
</div>
Controller 
• Used to "setup" your $scope (values) 
• Add behavior to your $scope (functions) 
• Don't do UI work using controllers!! 
• Use directives and filters instead 
18
¡Hola! v2.0 - View 
• Demo 
19 
<div ng-app="hola" ng-controller="NameController"> 
<div> 
First Name: <input type="text" ng-model="firstName"> 
</div> 
<div> 
Last Name: <input type="text" ng-model="lastName"> 
</div> 
<div> 
<b>Complete Name:</b> {{firstName + ' ' + lastName | uppercase}} 
</div> 
</div>
¡Hola! v2.0 - Controller 
• Demo 
20 
<script> 
(function(){ 
var app = angular.module('hola', []); 
app.controller('NameController', function($scope){ 
$scope.firstName='Angular'; 
$scope.lastName='rocks'; 
}); 
})(); 
</script>
Dependency Injection 
• Consider using array notation: 
app.controller('NameCtrl', function($scope){ ... }); 
app.controller('NameCtrl', ['$scope', function($scope){ ... }]); 
• Or use ngmin ng-annotate 
• grunt-ngmin, gulp-ngmin, grunt-ng-annotate, gulp-ng-annotate 
21
Expressions 
• {{ expression }} 
• No Control Flow Statements 
• Can use filters inside expressions: 
• {{ 'abcd' | uppercase }} 
22
Filters 
23 
...! 
<tr ng-repeat=! 
! "item in jobDefinitions | filter:filterQuery 
| orderBy:'name'">! 
...
Directives 
• Are markers on a DOM element 
• Attach behavior/transform DOM elements 
• ng-controller, ng-app ... 
24
Types of Directives 
• Attribute (default) 
• Element 
• Class 
• See: https://gist.github.com/CMCDragonkai/6282750 
25
Routing 
• ngRoute (built-in) 
• Routing on steroids using ui-router 
26
Routing using UI-Router 
• state machine 
• nested views 
• Spring XD's routes.js 
27
Modules 
• Hang on tight… 
28
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. 
botanic | NG
Build and Deployment 
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Build and Deployment 
• Do everything via Maven and Gradle? 
• What about Non-Java Tooling? 
• Consider Web Resource Optimization 
31
Web Resources Optimization 
• Minification 
• Merging 
• Compression 
• Caching (and Cache busting) 
32
Web Resources Optimization 
33
Strategies - Java Tooling 
• Wro4j 
• Jawr 
• Spring 4.1 
• Flexible resolution and transformation of 
static web resources 
• See Blog Post 
• WebJars 
34
Strategies - JavaScript Tooling 
• Node (Npm) 
• Grunt (Gulp) 
• Bower 
• Yeoman (angular-seed) 
35
Make Maven and Gradle Grunt 
• Plugins exist for Gradle and Maven 
• Spring XD uses Gradle integration 
• botanic-ng uses Maven integration 
• Spring Boot plus Maven Frontend Plugin 
36
Integration with Spring (Boot) 
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Hello World fits into Tweet 
38 
@Controller 
class ThisWillActuallyRun 
{ 
@RequestMapping("/") 
@ResponseBody 
String home() { 
"Hello World!" 
} 
}
Rapid Prototyping 
• Spring Scripts (Samples) 
• Starter POMs 
• Über-Jars support (can create WARs also) 
• Maven + Gradle Plugins 
• AutoConfiguration support 
39
Main is BACK 
40 
@EnableAutoConfiguration @ComponentScan @EnableScheduling 
public class MainApp extends RepositoryRestMvcConfiguration { 
@Override 
protected void configureRepositoryRestConfiguration( 
RepositoryRestConfiguration config) { 
config.exposeIdsFor(Image.class, Garden.class, Plant.class); 
config.setBaseUri(URI.create("/api")); 
} 
public static void main(String[] args) { 
final ConfigurableApplicationContext context = 
SpringApplication.run(MainApp.class, args); 
... 
} 
@Bean 
MultipartConfigElement multipartConfigElement() { ... } ... 
}
Security 
41 
• Best strategy in regards to plugging in Spring Security? 
• Authentication and Authorization 
• How does it affect Testing 
• Consider Spring Session 
• org.springframework.session.web.http.HttpSessionStrategy 
• HeaderHttpSessionStrategy (x-auth-token) 
• CookieHttpSessionStrategy
Serving Static Content 
• /META-INF/resources/ 
• /resources/ 
• /static/ 
• /public/ 
• Also supports WebJars 
• Make Boot modules (UI) Pluggable 
42
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. 
Demo Backend
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. 
Modularization
Modularization Now 
• AngularJS Modules 
• RequireJS 
45
AngularJS Modules 
• Compartmentalize sections of your application 
• Does not deal with script loading 
• https://docs.angularjs.org/guide/module 
46 
angular.module('myModule', []). 
config(function(injectables) { // provider-injector 
// This is an example of config block. 
}). 
run(function(injectables) { // instance-injector 
// Like a Main method 
});
RequireJS 
• RequireJS 
• JavaScript file 
and module loader 
• RequireJS Optimizer 
47 
require.config({ 
paths: { 
angular: '../lib/angular/angular', 
jquery: '../lib/jquery/jquery', 
bootstrap: '../lib/bootstrap/bootstrap', 
… 
}, 
shim: { 
angular: { 
exports: 'angular' 
}, 
bootstrap: { 
deps: ['jquery'] 
} 
} 
});
Modularization Future 
• ECMAScript 6 modules 
• AngularJS 2 is being written in ES6 
• Web Components 
48
Componentization using Directives 
• angular-masonry 
• cgBusy 
• ngGrowl 
• angular-google-maps 
• angular-leaflet-directive 
• AngularUI 
• Bootstrap directives 
49
File Upload 
• angular-file-upload (nervgh) 
• angular-file-upload (danialfarid) 
• File Reader 
• Traditional Post 
50
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. 
Testing
Testing 
• E2E testing with Protractor 
• Unit Testing using Karma and Jasmine 
• Consider using SauceLabs 
52
UI Considerations 
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
UI Consideration 
• Bootstrap (It is the baseline) 
• Keep your CSS maintainable with Less and Sass 
• Check your production results with YSlow and PageSpeed 
• Load your site from different corners of the planet using 
http://www.webpagetest.org/ 
54
© 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. 
Resources
Books 
56
Videos and More 
• Angular JS Website - Tutorial, Docs 
• Angular JS Youtube Channel 
• ng-conf has almost 30 session videos 
• Shaping up with Angular JS (Videos + Course) 
• Dan Wahlin - Videos and Bog 
• AngularJS Fundamentals In 60-ish Minutes 
• https://egghead.io/ 
• Ben Nadel Blog 
• Year of Moo 
57
Thank You! 
58 
Source Code + Preso: 
https://github.com/ghillert/botanic-ng 
Related Talks 
Spring 4 Web Applications (R. Stoyanchev) 
Deep dive into Spring WebSockets (S. Almar) 
Spring Boot for the Web Tier (D. Syer/P. Webb) 
Resource Handling in Spring MVC 4.1 (B. Clozel/R. Stoyanchev) 
Introducing RaveJS (J. Hann) 
Great single page apps need great backends (Adib Saikali)
Ad

Recommended

PDF
The Spring Update
Gunnar Hillert
 
PDF
Ajug - The Spring Update
Gunnar Hillert
 
PPTX
Spring Projects Infrastructure
Gunnar Hillert
 
KEY
S2GX 2012 - Spring Projects Infrastructure
Gunnar Hillert
 
PDF
Modular Test-driven SPAs with Spring and AngularJS
Gunnar Hillert
 
PDF
Spring Batch Performance Tuning
Gunnar Hillert
 
PDF
Gradle - Build System
Jeevesh Pandey
 
PPTX
04 integrate entityframework
Erhwen Kuo
 
PPTX
01 startoff angularjs
Erhwen Kuo
 
PPTX
Powershell For Developers
Ido Flatow
 
PPTX
03 integrate webapisignalr
Erhwen Kuo
 
PPTX
06 integrate elasticsearch
Erhwen Kuo
 
PPTX
Don't Wait! Develop Responsive Applications with Java EE7 Instead
WASdev Community
 
KEY
Using ActiveObjects in Atlassian Plugins
Atlassian
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
PDF
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
Kevin Sutter
 
PDF
PUC SE Day 2019 - SpringBoot
Josué Neis
 
PPTX
Java springboot microservice - Accenture Technology Meetup
Accenture Hungary
 
PDF
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
mfrancis
 
KEY
All your data belong to us - The Active Objects Plugin
Samuel Le Berrigaud
 
PDF
Apache Cayenne for WO Devs
WO Community
 
PPTX
Inside Azure Diagnostics
Michael Collier
 
PDF
COScheduler
WO Community
 
PDF
Introduction in the play framework
Alexander Reelsen
 
PDF
Deployment of WebObjects applications on FreeBSD
WO Community
 
PPTX
Next stop: Spring 4
Oleg Tsal-Tsalko
 
PPTX
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 
PPTX
2013 빅데이터 및 API 기술 현황과 전망- 윤석찬
Channy Yun
 
PPTX
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
Terry Cho
 

More Related Content

What's hot (20)

PPTX
01 startoff angularjs
Erhwen Kuo
 
PPTX
Powershell For Developers
Ido Flatow
 
PPTX
03 integrate webapisignalr
Erhwen Kuo
 
PPTX
06 integrate elasticsearch
Erhwen Kuo
 
PPTX
Don't Wait! Develop Responsive Applications with Java EE7 Instead
WASdev Community
 
KEY
Using ActiveObjects in Atlassian Plugins
Atlassian
 
PPTX
Spring boot Introduction
Jeevesh Pandey
 
PDF
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
Kevin Sutter
 
PDF
PUC SE Day 2019 - SpringBoot
Josué Neis
 
PPTX
Java springboot microservice - Accenture Technology Meetup
Accenture Hungary
 
PDF
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
mfrancis
 
KEY
All your data belong to us - The Active Objects Plugin
Samuel Le Berrigaud
 
PDF
Apache Cayenne for WO Devs
WO Community
 
PPTX
Inside Azure Diagnostics
Michael Collier
 
PDF
COScheduler
WO Community
 
PDF
Introduction in the play framework
Alexander Reelsen
 
PDF
Deployment of WebObjects applications on FreeBSD
WO Community
 
PPTX
Next stop: Spring 4
Oleg Tsal-Tsalko
 
PPTX
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 
01 startoff angularjs
Erhwen Kuo
 
Powershell For Developers
Ido Flatow
 
03 integrate webapisignalr
Erhwen Kuo
 
06 integrate elasticsearch
Erhwen Kuo
 
Don't Wait! Develop Responsive Applications with Java EE7 Instead
WASdev Community
 
Using ActiveObjects in Atlassian Plugins
Atlassian
 
Spring boot Introduction
Jeevesh Pandey
 
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
Kevin Sutter
 
PUC SE Day 2019 - SpringBoot
Josué Neis
 
Java springboot microservice - Accenture Technology Meetup
Accenture Hungary
 
RESTful OSGi Web Applications Tutorial - Khawaja S Shams & Jeff Norris
mfrancis
 
All your data belong to us - The Active Objects Plugin
Samuel Le Berrigaud
 
Apache Cayenne for WO Devs
WO Community
 
Inside Azure Diagnostics
Michael Collier
 
COScheduler
WO Community
 
Introduction in the play framework
Alexander Reelsen
 
Deployment of WebObjects applications on FreeBSD
WO Community
 
Next stop: Spring 4
Oleg Tsal-Tsalko
 
SenchaCon 2016: Develop, Test & Deploy with Docker - Jonas Schwabe
Sencha
 

Viewers also liked (7)

PPTX
2013 빅데이터 및 API 기술 현황과 전망- 윤석찬
Channy Yun
 
PPTX
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
Terry Cho
 
PPTX
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
Terry Cho
 
PPTX
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
Terry Cho
 
PPTX
대용량 분산 아키텍쳐 설계 #5. rest
Terry Cho
 
PDF
RESTful API Design, Second Edition
Apigee | Google Cloud
 
PPTX
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
Terry Cho
 
2013 빅데이터 및 API 기술 현황과 전망- 윤석찬
Channy Yun
 
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
Terry Cho
 
대용량 분산 아키텍쳐 설계 #2 대용량 분산 시스템 아키텍쳐 디자인 패턴
Terry Cho
 
대용량 분산 아키텍쳐 설계 #3 대용량 분산 시스템 아키텍쳐
Terry Cho
 
대용량 분산 아키텍쳐 설계 #5. rest
Terry Cho
 
RESTful API Design, Second Edition
Apigee | Google Cloud
 
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
Terry Cho
 
Ad

Similar to Creating Modular Test-Driven SPAs with Spring and AngularJS (20)

PPTX
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
PPTX
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
PDF
Introduction To Angular.js - SpringPeople
SpringPeople
 
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
PPTX
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
murtazahaveliwala
 
PDF
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Philipp Burgmer
 
PDF
Quick start with AngularJS
Iuliia Baranova
 
PPTX
Practical AngularJS
Wei Ru
 
PPTX
Angularjs basic part01
Mohd Abdul Baquee
 
PPTX
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
PPTX
Getting Started with Angular JS
Akshay Mathur
 
PPTX
AngularJS - a radically different way of building Single Page Apps
jivkopetiov
 
PPTX
AngularJS is awesome
Eusebiu Schipor
 
PDF
AngularJS Deep Dives (NYC GDG Apr 2013)
Nitya Narasimhan
 
PPTX
Angular JS, A dive to concepts
Abhishek Sur
 
PPTX
Angular JS - Introduction
Sagar Acharya
 
PPTX
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
PPTX
Angular js for Beginnners
Santosh Kumar Kar
 
PDF
AngularJS By Vipin
Vipin Mundayad
 
PPT
AngularJS Brownbag
Christopher Casad
 
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
AngularJS 1.x - your first application (problems and solutions)
Igor Talevski
 
Introduction To Angular.js - SpringPeople
SpringPeople
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
murtazahaveliwala
 
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Philipp Burgmer
 
Quick start with AngularJS
Iuliia Baranova
 
Practical AngularJS
Wei Ru
 
Angularjs basic part01
Mohd Abdul Baquee
 
AngularJS with TypeScript and Windows Azure Mobile Services
Rainer Stropek
 
Getting Started with Angular JS
Akshay Mathur
 
AngularJS - a radically different way of building Single Page Apps
jivkopetiov
 
AngularJS is awesome
Eusebiu Schipor
 
AngularJS Deep Dives (NYC GDG Apr 2013)
Nitya Narasimhan
 
Angular JS, A dive to concepts
Abhishek Sur
 
Angular JS - Introduction
Sagar Acharya
 
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
Angular js for Beginnners
Santosh Kumar Kar
 
AngularJS By Vipin
Vipin Mundayad
 
AngularJS Brownbag
Christopher Casad
 
Ad

More from Gunnar Hillert (10)

PDF
High Precision GPS Positioning for Spring Developers
Gunnar Hillert
 
PDF
Migrating to Angular 5 for Spring Developers
Gunnar Hillert
 
PPTX
s2gx2015 who needs batch
Gunnar Hillert
 
PDF
Atlanta JUG - Integrating Spring Batch and Spring Integration
Gunnar Hillert
 
PDF
DevNexus 2013 - Introduction to WebSockets
Gunnar Hillert
 
PDF
Introduction to WebSockets
Gunnar Hillert
 
KEY
S2GX 2012 - What's New in Spring Integration
Gunnar Hillert
 
KEY
S2GX 2012 - Introduction to Spring Integration and Spring Batch
Gunnar Hillert
 
PDF
Cloud Foundry for Spring Developers
Gunnar Hillert
 
KEY
jRecruiter - The AJUG Job Posting Service
Gunnar Hillert
 
High Precision GPS Positioning for Spring Developers
Gunnar Hillert
 
Migrating to Angular 5 for Spring Developers
Gunnar Hillert
 
s2gx2015 who needs batch
Gunnar Hillert
 
Atlanta JUG - Integrating Spring Batch and Spring Integration
Gunnar Hillert
 
DevNexus 2013 - Introduction to WebSockets
Gunnar Hillert
 
Introduction to WebSockets
Gunnar Hillert
 
S2GX 2012 - What's New in Spring Integration
Gunnar Hillert
 
S2GX 2012 - Introduction to Spring Integration and Spring Batch
Gunnar Hillert
 
Cloud Foundry for Spring Developers
Gunnar Hillert
 
jRecruiter - The AJUG Job Posting Service
Gunnar Hillert
 

Recently uploaded (20)

PPTX
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
PDF
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
PDF
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
PDF
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
PPTX
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PDF
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
PPTX
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
PDF
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
PDF
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
PDF
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
PDF
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
PDF
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
PPTX
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
PDF
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
PDF
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PDF
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
Mastering AI Workflows with FME by Mark Döring
Safe Software
 

Creating Modular Test-Driven SPAs with Spring and AngularJS

  • 1. Creating Modular Test Driven SPAs with Spring And AngularJS By Gunnar Hillert - @ghillert © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
  • 2. Goals • AngularJS Introduction • Build and Deployment • Integration with Spring • Modularization • Testing • UI Considerations 2
  • 3. Me • (Java) Web developer since 2005 • Struts 1+2, Spring MVC, GWT, Flex • Spring Integration + XD committer • AngularJS since Jan 2014 • Co-organize 3
  • 5. AngularJS Introduction © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
  • 6. Audience - What do you use*? • AngularJS • Backbone • JQuery • Are you using any other SPA Framework? Ember.js • Spring MVC • Spring Boot 6 60% 20% 80% 1 user 80% 20% * Recorded from memory
  • 7. What are SPAs? 7 A single-page application (SPA), also known as single-page interface (SPI), is a web application or web site that fits on a single web page with the goal of providing a more fluid user experience akin to a desktop application. Wikipedia
  • 9. JavaScript WTF • http://wtfjs.com/ 9 parseInt('crap'); // NaN parseInt('crap', 16);// 12 ! (2 + "3"); // 23 (2 + +"3"); // 5 (+""); // 0
  • 11. From Backbone to Angular • Too many moving parts, choices • Boilerplate Code • Marionette, Backbone.ModelBinder, Backbone.Relational 11
  • 13. AngularJS Basics • Model • View (Templates) • Controller • Dependency Injection • Expressions • Filters • Directives • Routing • Modules • See also: AngularJS Concepts 13
  • 14. Model • Angular is very flexible about your model • Ultimately expressed via the $scope • $scope = Glue between Controller and View • $scope mimics DOM (Hierarchical, one $rootScope) 14
  • 15. Model • Killer Feature: Data-Binding • Model === single-source-of-truth • View reflects model changes automatically • $watch, $apply 15
  • 16. View • HTML is your templating Engine • Minimize logic as much as possible • Consider Custom Directives 16
  • 17. ¡Hola! • Demo 17 <div ng-app ng-init="firstName='Eric';lastName='Cartman'"> <div> First Name: <input type="text" ng-model="firstName"> </div> <div> Last Name: <input type="text" ng-model="lastName"> </div> <div> <b>Complete Name:</b> {{firstName + ' ' + lastName | uppercase}} </div> </div>
  • 18. Controller • Used to "setup" your $scope (values) • Add behavior to your $scope (functions) • Don't do UI work using controllers!! • Use directives and filters instead 18
  • 19. ¡Hola! v2.0 - View • Demo 19 <div ng-app="hola" ng-controller="NameController"> <div> First Name: <input type="text" ng-model="firstName"> </div> <div> Last Name: <input type="text" ng-model="lastName"> </div> <div> <b>Complete Name:</b> {{firstName + ' ' + lastName | uppercase}} </div> </div>
  • 20. ¡Hola! v2.0 - Controller • Demo 20 <script> (function(){ var app = angular.module('hola', []); app.controller('NameController', function($scope){ $scope.firstName='Angular'; $scope.lastName='rocks'; }); })(); </script>
  • 21. Dependency Injection • Consider using array notation: app.controller('NameCtrl', function($scope){ ... }); app.controller('NameCtrl', ['$scope', function($scope){ ... }]); • Or use ngmin ng-annotate • grunt-ngmin, gulp-ngmin, grunt-ng-annotate, gulp-ng-annotate 21
  • 22. Expressions • {{ expression }} • No Control Flow Statements • Can use filters inside expressions: • {{ 'abcd' | uppercase }} 22
  • 23. Filters 23 ...! <tr ng-repeat=! ! "item in jobDefinitions | filter:filterQuery | orderBy:'name'">! ...
  • 24. Directives • Are markers on a DOM element • Attach behavior/transform DOM elements • ng-controller, ng-app ... 24
  • 25. Types of Directives • Attribute (default) • Element • Class • See: https://gist.github.com/CMCDragonkai/6282750 25
  • 26. Routing • ngRoute (built-in) • Routing on steroids using ui-router 26
  • 27. Routing using UI-Router • state machine • nested views • Spring XD's routes.js 27
  • 28. Modules • Hang on tight… 28
  • 29. © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. botanic | NG
  • 30. Build and Deployment © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
  • 31. Build and Deployment • Do everything via Maven and Gradle? • What about Non-Java Tooling? • Consider Web Resource Optimization 31
  • 32. Web Resources Optimization • Minification • Merging • Compression • Caching (and Cache busting) 32
  • 34. Strategies - Java Tooling • Wro4j • Jawr • Spring 4.1 • Flexible resolution and transformation of static web resources • See Blog Post • WebJars 34
  • 35. Strategies - JavaScript Tooling • Node (Npm) • Grunt (Gulp) • Bower • Yeoman (angular-seed) 35
  • 36. Make Maven and Gradle Grunt • Plugins exist for Gradle and Maven • Spring XD uses Gradle integration • botanic-ng uses Maven integration • Spring Boot plus Maven Frontend Plugin 36
  • 37. Integration with Spring (Boot) © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
  • 38. Hello World fits into Tweet 38 @Controller class ThisWillActuallyRun { @RequestMapping("/") @ResponseBody String home() { "Hello World!" } }
  • 39. Rapid Prototyping • Spring Scripts (Samples) • Starter POMs • Über-Jars support (can create WARs also) • Maven + Gradle Plugins • AutoConfiguration support 39
  • 40. Main is BACK 40 @EnableAutoConfiguration @ComponentScan @EnableScheduling public class MainApp extends RepositoryRestMvcConfiguration { @Override protected void configureRepositoryRestConfiguration( RepositoryRestConfiguration config) { config.exposeIdsFor(Image.class, Garden.class, Plant.class); config.setBaseUri(URI.create("/api")); } public static void main(String[] args) { final ConfigurableApplicationContext context = SpringApplication.run(MainApp.class, args); ... } @Bean MultipartConfigElement multipartConfigElement() { ... } ... }
  • 41. Security 41 • Best strategy in regards to plugging in Spring Security? • Authentication and Authorization • How does it affect Testing • Consider Spring Session • org.springframework.session.web.http.HttpSessionStrategy • HeaderHttpSessionStrategy (x-auth-token) • CookieHttpSessionStrategy
  • 42. Serving Static Content • /META-INF/resources/ • /resources/ • /static/ • /public/ • Also supports WebJars • Make Boot modules (UI) Pluggable 42
  • 43. © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. Demo Backend
  • 44. © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. Modularization
  • 45. Modularization Now • AngularJS Modules • RequireJS 45
  • 46. AngularJS Modules • Compartmentalize sections of your application • Does not deal with script loading • https://docs.angularjs.org/guide/module 46 angular.module('myModule', []). config(function(injectables) { // provider-injector // This is an example of config block. }). run(function(injectables) { // instance-injector // Like a Main method });
  • 47. RequireJS • RequireJS • JavaScript file and module loader • RequireJS Optimizer 47 require.config({ paths: { angular: '../lib/angular/angular', jquery: '../lib/jquery/jquery', bootstrap: '../lib/bootstrap/bootstrap', … }, shim: { angular: { exports: 'angular' }, bootstrap: { deps: ['jquery'] } } });
  • 48. Modularization Future • ECMAScript 6 modules • AngularJS 2 is being written in ES6 • Web Components 48
  • 49. Componentization using Directives • angular-masonry • cgBusy • ngGrowl • angular-google-maps • angular-leaflet-directive • AngularUI • Bootstrap directives 49
  • 50. File Upload • angular-file-upload (nervgh) • angular-file-upload (danialfarid) • File Reader • Traditional Post 50
  • 51. © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. Testing
  • 52. Testing • E2E testing with Protractor • Unit Testing using Karma and Jasmine • Consider using SauceLabs 52
  • 53. UI Considerations © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission.
  • 54. UI Consideration • Bootstrap (It is the baseline) • Keep your CSS maintainable with Less and Sass • Check your production results with YSlow and PageSpeed • Load your site from different corners of the planet using http://www.webpagetest.org/ 54
  • 55. © 2014 SpringOne 2GX. All rights reserved. Do not distribute without permission. Resources
  • 57. Videos and More • Angular JS Website - Tutorial, Docs • Angular JS Youtube Channel • ng-conf has almost 30 session videos • Shaping up with Angular JS (Videos + Course) • Dan Wahlin - Videos and Bog • AngularJS Fundamentals In 60-ish Minutes • https://egghead.io/ • Ben Nadel Blog • Year of Moo 57
  • 58. Thank You! 58 Source Code + Preso: https://github.com/ghillert/botanic-ng Related Talks Spring 4 Web Applications (R. Stoyanchev) Deep dive into Spring WebSockets (S. Almar) Spring Boot for the Web Tier (D. Syer/P. Webb) Resource Handling in Spring MVC 4.1 (B. Clozel/R. Stoyanchev) Introducing RaveJS (J. Hann) Great single page apps need great backends (Adib Saikali)