Grails 3.0先取り!? Spring Boot入門ハンズオン #jggug_bootToshiaki Maki
Spring Bootのハンズオン資料です。
----
Grailsの次期バージョン3.0でベースになることが予定されている、Spring界隈の新しいトレンド"Spring Boot"のハンズオンを通じて、Spring Bootのイメージを掴んでもらいたいと思います。内容は以下の通りです。
Spring Boot概要説明
Spring Bootを用いて簡単なアプリケーションを実際に作ってみる
(合計で約二時間弱)
This document provides an overview of the history and key components of the Spring framework. It outlines the acquisitions of VMware, Pivotal Labs, and Dell that contributed to Spring's development. It also summarizes the major releases of Spring and describes some of its core modules for IOC, AOP, data access, security, integration, and more.
Cloud Foundy Java Client V 2.0 #cf_tokyoToshiaki Maki
The document summarizes the changes made to the Cloud Foundry Java client between version 1 and version 2. Version 1 had problems with being monolithic, blocking, and dependent on Spring Framework. Version 2 addresses these by separating the client into modules, supporting non-blocking reactive streams, and not requiring Spring. It also improves the API design by removing overloading and simplifying usage.
This document demonstrates a continuous integration and delivery workflow using Concourse CI to deploy code changes through development, staging, and production environments on Cloud Foundry. It shows how features are developed on branches off of develop, merged to develop after testing, and later merged into release branches and deployed through the environments after additional testing before being promoted to production.
The document summarizes the key features and highlights of Spring Boot 1.3, which is scheduled for release in September 2015. Some of the main things covered include Spring 4.2 support, new auto-configurations for caching, OAuth2, and other components, improvements to non-functional aspects like metrics export, and enhancements to DevOps tools including a systemd service generator and improved development tools. Upcoming user group events related to Spring are also announced.
This document introduces Concourse CI, an open source continuous integration and delivery tool. It provides an overview of Concourse and compares it to Jenkins. It describes Concourse's architecture including tasks, resources, jobs and pipelines. It then explains how to install Concourse using Vagrant, executable binaries or BOSH. Finally it provides examples of simple "hello world" and more advanced Java project and Cloud Foundry deployment pipelines.
This document discusses how to install Concourse CI using BOSH on AWS and Azure. It provides steps to set up the necessary infrastructure like VPC, security groups, install BOSH Director. It then covers uploading stemcells and releases, creating the BOSH manifest file, and deploying Concourse. The document emphasizes that BOSH allows provisioning Concourse in a production-ready, scalable way and provides samples for AWS and Azure deployments.
This document provides an overview of Cloud Foundry, including:
- Cloud Foundry is an open source cloud application platform that allows developers to build, deploy, and run applications.
- It describes the architecture of Cloud Foundry including the cloud controller, cells, buildpacks, and how applications are deployed and scaled.
- It also discusses services on Cloud Foundry, including the marketplace, creating and binding services, and accessing service credentials.
Short Lived Tasks in Cloud Foundry #cfdtokyoToshiaki Maki
The document discusses different types of tasks in Cloud Foundry including long-running process (LRP) tasks, app process staging tasks, and app tasks. It provides examples of using the cf v3-run-task command to run tasks such as database migrations, flyway migrations, and a custom task to output a greeting.
Implement Service Broker with Spring Boot #cf_tokyoToshiaki Maki
This document discusses implementing a service broker with Spring Boot to provide services to applications running on Cloud Foundry. It provides an overview of service brokers and their APIs in Cloud Foundry. It then demonstrates how to build a sample fake service broker using Spring Boot and the Spring Cloud CloudFoundry Service Broker library by implementing the broker APIs and services. The broker is deployed locally to PCF Dev and services are created and bound to applications.
From Zero to Hero with REST and OAuth2 #jjugToshiaki Maki
The document discusses authorization using OAuth2 and securing REST APIs. It begins with an introduction to OAuth2 terminology and flow, including the authorization code grant and resource owner password credentials grant types. It then covers using JSON Web Tokens (JWTs) as access tokens, explaining that JWTs can be verified at startup without calling the authorization server for each request, unlike plain access tokens. The document concludes with links to code samples for implementing OAuth2 in Spring.
Team Support in Concourse CI 2.0 #concourse_tokyoToshiaki Maki
The document discusses new team support features in Concourse CI 2.0. It introduces the ability to have multiple teams with separate pipelines and builds. Authentication and authorization can now be configured separately for each team using various providers like Basic auth, GitHub teams, Cloud Foundry UAA, and generic OAuth 2. Commands to configure the authentication for each team using the different providers are also shown.
The document discusses Spring Cloud services. It describes how to implement a configuration server, service registry, and circuit breaker dashboard locally using Spring Cloud. It then explains how these same patterns and services can be provided on Pivotal Cloud Foundry as managed services, including how to create and bind the services in Cloud Foundry.
From Spring Boot 2.2 to Spring Boot 2.3 #jsugToshiaki Maki
Spring Boot 2.3 will include improvements to support for containers and Kubernetes, as well as updates for Spring Framework 5.3 including support for JDK 17 LTS and GraalVM native images. Other new features in Spring Boot 2.3 include enhancements to Spring Data and a target release date of April 2020. Spring Framework 5.3 will build upon features introduced in 5.x such as RSocket and coroutines.
The document discusses a meetup about integrating Concourse and Spinnaker. It covers why Spinnaker is useful for continuous delivery, specifically blue/green deployments, rollbacks, and automated canary analysis. It then discusses how Concourse and Spinnaker can be integrated using the Concourse Spinnaker resource to trigger Spinnaker pipelines from Concourse and vice versa. A demo is shown of building a Docker image, deploying it to Spinnaker, running tests with JMeter, and rolling back if tests fail.
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tToshiaki Maki
This document summarizes a presentation about serverless computing using Spring Cloud Function, Knative, and riff. It discusses what serverless computing is, an overview of Spring Cloud Function for developing serverless applications, and how Knative and riff can be used as platforms to deploy serverless workloads on Kubernetes. Code examples are provided to demonstrate invoking functions via HTTP and messaging with Spring Cloud Function and deploying functions to Knative and riff.
Spring Boot Actuator 2.0 & Micrometer #jjug_ccc #ccc_a1Toshiaki Maki
Spring Boot Actuator 2.0 provides additional monitoring endpoints for Spring Boot applications running in production. Micrometer allows instrumenting Spring Boot applications without vendor lock-in by providing common metrics that can be exported to systems like Prometheus, Datadog, and Cloud Foundry Metrics. Key features include multi-dimensional metrics with tags instead of hierarchies, histograms for response time distributions, and client-side percentiles. Monitoring of Spring Boot applications can be done on Cloud Foundry by scraping the /actuator/prometheus endpoint across application instances behind a load balancer.
Spring Boot Actuator 2.0 has been refactored and now supports Micrometer for instrumentation and metrics collection. Micrometer allows instrumentation without vendor lock-in and supports many monitoring systems including Prometheus, Datadog, and Cloud Foundry Metrics. New features in Spring Boot Actuator 2.0 include support for Spring WebFlux, more secure configuration of endpoints, and histograms and percentiles for more detailed metrics. Micrometer provides a common API for instruments like timers, counters, and gauges and supports adding custom meters.
Open Service Broker APIとKubernetes Service Catalog #k8sjpToshiaki Maki
The document discusses the Open Service Broker API and Kubernetes Service Catalog. It describes how the Service Broker API allows developers to provision and bind to services outside of Kubernetes. It then explains how the Kubernetes Service Catalog implements the Service Broker API to provide services within Kubernetes using new resource types like ServiceInstance and ServiceBinding. The document provides examples of installing brokers, listing available services, and creating instances and bindings.
Spring Cloud Function & Project riff #jsugToshiaki Maki
This document discusses Spring Cloud Function and Project Riff. It provides an overview of serverless computing and functions-as-a-service (FaaS). It introduces Spring Cloud Function as a way to write functions in Spring Boot and deploy them to various FaaS providers. It also describes Project Riff, an open source FaaS platform that runs on Kubernetes and provides event-driven functions through containers and sidecars that connect functions to event brokers. It demonstrates packaging functions as containers and connecting them to brokers through sidecars to handle event streaming and scaling of functions.
Introduction to Spring WebFlux #jsug #sf_a1Toshiaki Maki
The document provides an introduction and overview of Spring WebFlux, a non-blocking web framework for Spring. It discusses the differences between blocking and non-blocking web stacks, and how Spring WebFlux uses reactive streams and programming. Code examples are provided showing how to build reactive controllers and streams in Spring WebFlux that support backpressure.
BOSH / CF Deployment in modern ways #cf_tokyoToshiaki Maki
1. The document discusses deploying BOSH and Cloud Foundry using the BOSH CLI v2. It covers the general BOSH deployment workflow, differences between BOSH CLI v1 and v2, maintaining manifest files using operation files, downloading BOSH releases, variable interpolation, and provisioning the BOSH director.
2. It also provides examples of deploying Concourse on a single VM without a BOSH director using the BOSH CLI create-env command and different infrastructure configurations.
Why PCF is the best platform for Spring BootToshiaki Maki
Pivotal Cloud Foundry (PCF) provides many out-of-the-box features for managing and operating Spring Boot apps, including a cloud profile, Spring Cloud Connectors, Spring Cloud Services, a Trace Exporter, Spring Actuator support in Apps Manager, and a Metrics Forwarder Service. These features simplify development and operations of microservices built with Spring technologies when deployed to PCF.
This document provides instructions for installing and configuring Zipkin, an open source distributed tracing system. It describes how to download Zipkin, configure it to store traces in MySQL or Elasticsearch, and receive traces from Kafka. It also covers enabling OAuth2 authentication and securing the Zipkin UI and API endpoints.
The document discusses various boilerplate patterns related to building microservices using the Spring Framework and Spring Cloud. It outlines patterns for application coordination, configuration, operations for the JVM, runtime platform provisioning, and microservice operations. It also introduces Spring Cloud projects like Config Server, Eureka, Ribbon, Hystrix, Stream, and Sleuth that can help implement these patterns to build cloud-native microservice architectures.
Spring Framework 5.0による Reactive Web Application #JavaDayTokyoToshiaki Maki
The document discusses reactive programming and the Spring Framework 5.0 release. It provides an overview of reactive programming concepts like asynchronous non-blocking applications. It also discusses Reactive Streams and libraries like Reactor. Finally, it covers new features in Spring Framework 5.0 like performance improvements, support for JDK 9, and the introduction of reactive APIs in Spring.
The document discusses various topics related to Spring Boot including Spring Data REST, CSRF protection, and Cloud Foundry integration. It provides code examples for exposing repositories as REST APIs with Spring Data REST, handling errors and exceptions, and securing applications with CSRF tokens. It also briefly mentions Spring Boot features like configuration properties and the Actuator.
The document discusses Kotlin support in Spring Framework 5. It covers how Kotlin can be used with Spring Boot and Spring's programming model through features like extension functions and reified type parameters. It provides code examples of using Kotlin idioms with Spring components like the application context, JdbcTemplate, and RestTemplate to make the code more concise and readable. It also briefly mentions new features in Spring Framework 5 like reactive support using Spring WebFlux and using router functions with Kotlin.
Event Driven Microservices with Spring Cloud Stream #jjug_ccc #ccc_ab3Toshiaki Maki
The document describes Spring Cloud Stream, an event-driven microservice framework built on Spring Boot and Spring Integration. It provides primitives for building message-driven microservices including persistent publish-subscribe messaging, consumer groups, and support for multiple message brokers like RabbitMQ and Kafka. Applications are developed as message sources, sinks and processors. Spring Cloud Stream handles mapping of applications to messaging infrastructure.
Managing your Docker image continuously with Concourse CIToshiaki Maki
This document discusses managing Docker images continuously using Concourse CI. It describes using a Docker image resource in a Concourse pipeline configuration file to build a custom Docker image. The pipeline pulls from a Git repository, builds the image using a Dockerfile, and pushes the new image to a registry on each run, ensuring the image is always up to date.
Data Microservices with Spring Cloud Stream, Task, and Data Flow #jsug #spri...Toshiaki Maki
The document discusses Spring Cloud Data Flow, which provides a framework for building data pipelines using microservices. It describes how Spring Cloud Data Flow orchestrates long-lived streaming applications using Spring Cloud Stream and short-lived batch processing applications using Spring Cloud Task. It also discusses how these applications can be deployed on modern platforms using deployment-specific Spring Cloud Deployers.
19. Spring Ecosystem
IDE
Spring Tool Suite (STS)
RAD
Starter
Spring Roo
Web
Spring XD
Spring WebFlow
Spring
Security
OAuth
Spring MVC
Spring
Security
Social
Big Data
Security
Spring Data Rest
Spring Mobile
Spring Boot
DataAccess
Spring Hadoop
Batch
Spring Data
MongoDB
Spring Data
JPA
Spring Batch
Enterprise
Integration
Spring
Integration
Core
Spring DI
Spring AOP
Spring TX
Spring Social
Github
Spring Social
Facebook
Spring Social
Twitter
20. Spring Ecosystem
今日のスコープ
IDE
Spring Tool Suite (STS)
RAD
Starter
Spring Boot
Spring Roo
Web
Spring XD
Spring Data
Rest
Spring WebFlow
Spring
Security
OAuth
Spring MVC
Spring
Security
Spring Mobile
Social
Big Data
Security
DataAccess
Spring Hadoop
Batch
Spring Data
MongoDB
Spring Data
JPA
Spring Batch
Enterprise
Integration
Spring
Integration
Core
Spring DI
Spring AOP
Spring TX
Spring Social
Github
Spring Social
Facebook
Spring Social
Twitter
23. Spring DI x AOP
•
成熟度:★★★ version: 3.2.5.RELEASE
•
Spring Ecosystemのコア
•
JavaConfigサポート(@Configuration, @Bean)
•
•
No XML hell!
JSR-330サポート(@Inject, @Named)
24. JSR-330によるDI コード例
package sample;
import javax.inject.Named;
!
@Named
public class GreetingService {
public String hello(String message) {
return "Hello " + message + "!";
}
}
package sample;
import javax.inject.Inject;
!
public class MyApplication {
@Inject
GreetingService service;
public void run(String message) {
System.out.println(service.hello(message));
}
}
25. JSR-330によるDI コード例
@Configuration
@ComponentScan(basePackages = "sample")
public class AppConfig {
@Bean
MyApplication myApplication() {
return new MyApplication();
}
}
デフォルトでscope=singleton
になるので注意
Google Guiceよりも簡単!
public class EntryPoint {
public static void main(String[] args) {
try (GenericApplicationContext context = new
AnnotationConfigApplicationContext(
AppConfig.class);) {
MyApplication app = context.getBean(MyApplication.class);
app.run("World!");
}
}
}
39. Spring Data
• 成熟度:★★☆
• データアクセスの抽象化ライブラリ
• オブジェクトマッピング、Repository、Templateを提供
• いろいろなデータストアをサポートするサブプロジェクトからなる
• Spring
Data Commons
• Spring
Data JPA
• Spring
Data MongoDB, Redis, Neo4j, REST, Hadoop, HBase,
Solr, ...
• 各データストアにRepositoryやTemplateを提供してBoilerplateをな
くす
40. 従来のJPAプログラミング
@Entity
public class Customer {
@Id
@GeneratedValue
private Long id;
private String firstname;
private String lastname;
// omitted…
}
毎回同じような
コード・・・→
@Repository
public class CustomerRepository {
@PersistenceContext EntityManager em;
public Customer findOne(Long id) {
return em.find(Customer.class, id);
}
public List<Customer> findAll(int page, int size) {
TypedQuery<Customer> query = em
.createQuery("SELECT x FROM Customer x", Customer.class)
.setFirstResult(page * size).setMaxResults(size);
return query.getResultList();
}
@Transactional
public Customer save(Customer customer) {
if (customer.getId() == null) {
em.persist(customer);
return customer;
} else {
return em.merge(customer);
}
}
public List<Customer> findByLastname(String lastname) {
TypedQuery<Customer> query = em.createQuery(
"SELECT x FROM Customer x WHERE x.lastname = :lastname",
Customer.class).setParameter("lastname", lastname);
return query.getResultList();
}
}
41. Spring Data JPAを使うと・・
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
!
public interface CustomerRepository extends JpaRepository<Customer, Long> {
@Query("SELECT x FROM Customer x WHERE x.lastname = :lastname")
public List<Customer> findByLastname(@Param("lastname") String lastname);
}
•
たったこれだけ!
•
CRUD系のメソッド、ページング・ソート処理は自動で
実装される
•
JPAプログラミングの簡素化!
42. Spring Data REST
•
成熟度:★☆☆ version: 1.1.0.M1
•
Spring DataのRepositoryをREST APIにエクス
ポート(@RestResource)
•
現在はSpringMVCのみサポートしていrが、将
来的にはServlet非依存を目指している
•
HypermediaLinkの作成
47. 速習 Spring Boot
$ brew tap pivotal/tap
$ brew install springboot
$ which spring
/usr/local/bin/spring
$ spring run app.groovy
// app.groovy
@Controller
class Application {
@RequestMapping("/")
@ResponseBody
def String hoge() {
"HelloWorld!"
}
}
初回のみ
for Macユーザー
ソースコード全文。import文不要
51. Lambdaサポート
@Inject
JdbcTemplate jdbcTemplate;
!
Before
public void foo() {
User user = jdbcTemplate.queryForObject(
"SELECT userId, userName from User",
new RowMapper<User>() {
public User mapRow(java.sql.ResultSet rs, int rowNum)
throws java.sql.SQLException {
return new User(rs.getLong(1), rs.getString(2));
}
}
);
}
52. Lambdaサポート
@Inject
JdbcTemplate jdbcTemplate;
!
Before
public void foo() {
User user = jdbcTemplate.queryForObject(
"SELECT userId, userName from User",
new RowMapper<User>() {
public User mapRow(java.sql.ResultSet rs, int rowNum)
throws java.sql.SQLException {
return new User(rs.getLong(1), rs.getString(2));
}
}
);
}
After
53. Lambdaサポート
@Inject
JdbcTemplate jdbcTemplate;
!
Before
public void foo() {
User user = jdbcTemplate.queryForObject(
"SELECT userId, userName from User",
new RowMapper<User>() {
public User mapRow(java.sql.ResultSet rs, int rowNum)
throws java.sql.SQLException {
return new User(rs.getLong(1), rs.getString(2));
}
}
);
}
After
54. Lambdaサポート
@Inject
JdbcTemplate jdbcTemplate;
!
Before
public void foo() {
User user = jdbcTemplate.queryForObject(
"SELECT userId, userName from User",
new RowMapper<User>() {
public User mapRow(java.sql.ResultSet rs, int rowNum)
throws java.sql.SQLException {
return new User(rs.getLong(1), rs.getString(2));
}
}
);
}
SpringにはTemplateパターン+
コールバックな機能が多いので
ラムダ式の恩恵が大きい!
After
83. 最近のWebアプリ
Spring DI x AOP
Spring MVC
Bean Validation
Router
Spring
REST API
Model/
Collection
View
Template
JavaScript Framework
(Backbone.js, Angular.js, Knockout.js, …)
Spring Data JPA
JPA
84. 最近のWebアプリ
Spring DI x AOP
Spring MVC
Bean Validation
Spring
REST API
Spring Data JPA
JPA
Thin化するサーバーサイド
Router
Model/
Collection
View
Template
JavaScript Framework
(Backbone.js, Angular.js, Knockout.js, …)
Rich化するクライアントサイド
92. Java EEによる伝統的なWebアプリ
UI & Presentation
Layer
Service Layer
Persistence Layer
CDI and DI (JSR 299, 330)
JAX-RS
JSF
EJB
JPA
Bean Validation
Apache Shiro?
DB
Browser/Client
93. Springによる最近のWebアプリ
Spring DI x AOP
Spring MVC
Bean Validation
Router
Spring
REST API
Model/
Collection
View
Template
JavaScript Framework
(Backbone.js, Angular.js, Knockout.js, …)
Spring Data JPA
JPA
109. Spring Framework or Java EE個人的まとめ
Javaを
YES
Spring以外のJavaフレーム
ワークにもあてはまるフロー
使っている
だと思う
今
NO
Springを使って
いる
Spring
の将来に不安な
し
新しい機能
を使いたい
Java EE
Spring