#jjug_ccc #ccc_gh5 what's new in spring framework 4.3 / boot 1.4 + pivotal's cloud native...
Post on 06-Jan-2017
4.246 Views
Preview:
TRANSCRIPT
What's new in Spring Framework 4.3/Boot 1.4
+Pivotal's Cloud Native Approach
2016/05/21 JJUG CCC 2016 SpringToshiaki Maki (@making)Sr. Solutions Architect @Pivotal#jjug_̲ccc #ccc_̲gh5
Who am I ?•Toshiaki Maki (@making)•https://blog.ik.am•Sr. Solutions Architect•Spring Framework enthusiast
SpringFramework徹底⼊入⾨門(Coming Soon?)
パーフェクトJava EE(Coming Soon?)
Agenda•Spring Boot 1.4 / Spring Framework 4.3•Spring Framework 5.0•Spring Cloud•Go to Cloud Native
Spring Boothttps://twitter.com/phillip_̲webb/status/641444531867680768
Spring Initializr https://start.spring.io/
Spring Initializr https://start.spring.io/
Spring Initializr https://start.spring.io/
Spring Boot Adoption
RoadmapSpring Framework
Spring Boot
2016 JUN 2017〜~
4.3 GA
1.4 GA
5.0 RC1
2.0 GA
5.0 M1 5.0 GA
Spring Boot 1.4•Banner Update•Test Improvements•Spring Framework 4.3 Support•Misc
https://github.com/spring-‐‑‒projects/spring-‐‑‒boot/wiki/Spring-‐‑‒Boot-‐‑‒1.4-‐‑‒Release-‐‑‒Notes
Spring Boot 1.4•Banner Update•Test Improvements•Spring Framework 4.3 Support•Misc
https://github.com/spring-‐‑‒projects/spring-‐‑‒boot/wiki/Spring-‐‑‒Boot-‐‑‒1.4-‐‑‒Release-‐‑‒Notes
Spring Boot with Banner
👈
Spring Boot with Banner
src/main/resrouces/banner.txt
•1.1 supported Custom Text Banner
Spring Boot with Banner•1.3 supported ANSI Color Banner
${AnsiColor.BRIGHT_GREEN}My Application ${AnsiColor.BRIGHT_YELLOW}Hello!!${AnsiColor.DEFAULT}
src/main/resrouces/banner.txt
IntelliJ IDEA's Support
Nyan Cat!
https://github.com/snicoll-‐‑‒demos/spring-‐‑‒boot-‐‑‒4tw-‐‑‒uni/blob/master/spring-‐‑‒boot-‐‑‒4tw-‐‑‒web/src/main/resources/banner.txt
https://ja.wikipedia.org/wiki/Nyan_̲Cat
Spring Boot with Banner•1.4 supports Image Banner!!
Spring Boot with Banner•1.4 supports Image Banner!!
src/main/resrouces/banner.png
Spring Boot with Banner•1.4 supports Image Banner!!
src/main/resrouces/banner.png
Tweetyour banner
#tweetbootbanner
Spring Boot 1.4•Banner Update•Test Improvements•Spring Framework 4.3 Support•Misc
https://github.com/spring-‐‑‒projects/spring-‐‑‒boot/wiki/Spring-‐‑‒Boot-‐‑‒1.4-‐‑‒Release-‐‑‒Notes
Test Improvements•Test simplifications•Mocking and spying•Testing application slices
Test simplifications
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(MyApp.class) @WebIntegrationTest(randomPort=true)public class MyTest {
TestRestTemplate rest = new RestTemplate();@Value("${local.server.port}") int port;@Testpublic test() {rest.getForObject("http://localhost:"+port+"/foo",
String.class);}
}
~∼ Spring Boot 1.3
Test simplifications
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)public class MyTest {
TestRestTemplate rest = new RestTemplate();@LocalServerPort int port;@Testpublic test() {rest.getForObject("http://localhost:"+port+"/foo",
String.class);}
}
Spring Boot 1.4 ~∼
Test simplifications
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)public class MyTest {
TestRestTemplate rest = new RestTemplate();@LocalServerPort int port;@Testpublic test() {rest.getForObject("http://localhost:"+port+"/foo",
String.class);}
}
Spring Boot 1.4 ~∼• WebEnvironment.DEFINED_PORT• WebEnvironment.MOCK
Test simplifications
@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)public class MyTest {
@AutowiredTestRestTemplate rest;
@Testpublic test() {rest.getForObject("/foo", String.class);
}}
Spring Boot 1.4 ~∼
equals tohttp://localhost:${local.server.port}
Mocking and spying
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(MyApp.class) @WebIntegrationTest(randomPort=true)public class MyTest {
@Autowired FooController fooController;@Testpublic test() {FooService fooService = mock(FooService.class);fooController.fooService = fooService;// stubbing behaviors
}}
~∼ Spring Boot 1.3
Mocking and spying
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(MyApp.class) @WebIntegrationTest(randomPort=true)public class MyTest {
@MockBean // or @SpyBeanFooService fooService;
public test() {// stubbing behaviors
}}
Spring Boot 1.4 ~∼
Mocks will be automatically reset across tests
Testing application slices•Testing the JPA slice•Testing the Spring MVC slice•Testing the JSON slice
for fast tests(without Embedded Server)
Testing the JPA slice@RunWith(SpringRunner.class)@DataJpaTestpublic class UserRepositoryTests {
@Autowired TestEntityManager em;@Autowired UserRepository repository;
@Testpublic void test() {em.persist(new User("maki", 20));User user = this.repository.findByUsername("maki"); assertThat(user.getUsername()).isEqualTo("maki");assertThat(user.getAge()).isEqualTo(20);}
}
Test data creation
Testing the Spring MVC slice@RunWith(SpringRunner.class) @WebMvcTest(FooController.class)public class FooControllerTests {
@Autowired MockMvc mvc;@MockBean FooService fooService;
@Test public void test() {given(fooService.getFoo("xyz")).willReturn("bar");mvc.perform(get("/foo")
.andExpect(status().isOk())
.andExpect(content().string("bar"));}
}
Testing the Spring MVC slice@RunWith(SpringRunner.class) @WebMvcTest(FooController.class)public class FooControllerTests {
@Autowired WebClient webClient; // using HtmlUnit@MockBean FooService fooService;
@Test public void test() {given(fooService.getFoo("xyz")).willReturn("bar");HtmlPage page = webClient.getPage("/foo");HtmlForm form = page.getHtmlElementById("fooForm");// ...
} }
Testing the Spring MVC slice
@RunWith(SpringRunner.class) @WebMvcTest(FooController.class)public class FooControllerTests {
@Autowired WebDriver webDriver; // using Selenium@MockBean FooService fooService;
@Test public void test() {given(fooService.getFoo("xyz")).willReturn("bar");// ...
} }
Testing the JSON slice@RunWith(SpringRunner.class)@JsonTestpublic class MyJsonTests {
JacksonTester<VehicleDetails> json;@Test public void testSerialize() {VehicleDetails details =
new VehicleDetails("Honda", "Civic");assertThat(json.write(details))
.isEqualToJson("expected.json"); assertThat(json.write(details))
.extractingJsonPathStringValue("@.make")
.isEqualTo("Honda");}
}
Testing the JSON slice@RunWith(SpringRunner.class)@JsonTestpublic class MyJsonTests {
JacksonTester<VehicleDetails> json;@Test public void testDeserialize() {String json =
"{¥"make¥":¥"Ford¥",¥"model¥":¥"Focus¥"}"; assertThat(json.parse(json))
.isEqualTo(new VehicleDetails("Ford", "Focus")); assertThat(json.parseObject(json).getMake())
.isEqualTo("Ford"); }
}
Spring Boot 1.4•Banner Update•Test Improvements•Spring Framework 4.3 Support•Misc
https://github.com/spring-‐‑‒projects/spring-‐‑‒boot/wiki/Spring-‐‑‒Boot-‐‑‒1.4-‐‑‒Release-‐‑‒Notes
Spring Framework 4.3• Last 4.x feature release!• 4.3 RC1: April 6th• 4.3 GA: June 1st, 2016
• DI & MVC refinements• Composed annotations• Extended support life until 2020• on JDK 6, 7, 8 (and JDK 9 on a best-‐‑‒effort basis)• on Tomcat 6, 7, 8.0, 8.5 (and on best-‐‑‒effort 9.0)• on WebSphere 7, 8.0, 8.5 and 9 (Classic + Liberty)
from Keynote @ Spring IO 2016
Spring Framework 4.3• Implicit constructor injection• InjectionPoint like CDI• ....
• Composed annotations for @RequestMapping• Composed annotations for web @Scopes• @SessionAttribute/@RequestAttribute ...
http://docs.spring.io/spring/docs/4.3.0.RC2/spring-‐‑‒framework-‐‑‒reference/htmlsingle/#new-‐‑‒in-‐‑‒4.3
Core
Web
Implicit constructor injection
@RestControllerpublic class FooController {
private final FooService fooService;
@Autowiredpublic FooController(FooService fooService) {this.fooService = fooService;
}}
~∼ Spring 4.2
👈
Implicit constructor injection
@RestControllerpublic class FooController {
private final FooService fooService;
public FooController(FooService fooService) {this.fooService = fooService;
}}
Spring 4.3 ~∼
👍
Implicit constructor injection
@RestController@AllArgsConstructor(onConstructor = @_(@Autowired)) public class FooController {
private final FooService fooService;}
~∼ Spring 4.2 + Lombok
👇😩
Implicit constructor injection
@RestController@AllArgsConstructorpublic class FooController {
private final FooService fooService;}
Spring 4.3 ~∼ + Lombok
👍
InjectionPoint like CDI
@RestControllerpublic class FooController {
@Autowired@Xyz("bar")FooService service;
}
InjectionPoint like CDI@Configurationpublic class FooConfig {
@BeanFooService foo(InjectionPoint ip) {AnnotatedElement elm
= ip.getAnnotatedElement();Xyz xyz = elm.getAnnotation(Xyz.class);String value = xyz.value(); // "bar"// create FooService using Xyz's value
}}
Composed annotations for@RequestMapping
•@GetMapping•@PostMapping•@PutMapping•@DeleteMapping•@PatchMapping
@RestControllerpublic class FooController {
@RequestMapping(path = "foo", method = GET)String getFoo() {/* ... */}
@RequestMapping(path = "foo", method = POST)String postFoo() {/* ... */}
}
Spring 4.2
Composed annotations for@RequestMapping
@RestControllerpublic class FooController {
@GetMapping(path = "foo")String getFoo() {/* ... */}
@PostMapping(path = "foo")String postFoo() {/* ... */}
}
Spring 4.3
Composed annotations for@RequestMapping
@RestControllerpublic class FooController {
@GetMapping("foo")String getFoo() {/* ... */}
@PostMapping("foo")String postFoo() {/* ... */}
}
Spring 4.3
Composed annotations for@RequestMapping
Composed annotations forweb @Scope s
•@RequestScope•@SessionScope•@ApplicationScope
@Scope("request", proxyMode=TARGET_CLASS)public class RequestScopeBean {}
@Scope("session", proxyMode=TARGET_CLASS)public class SessionScopeBean {}
@Scope("application", proxyMode=TARGET_CLASS)public class ApplicationScopeBean {}
~∼Spring 4.2
Composed annotations forweb @Scope s
@RequestScopepublic class RequestScopeBean {}
@SessionScopepublic class SessionScopeBean {}
@ApplicationScopepublic class ApplicationScopeBean {}
Spring 4.3
Composed annotations forweb @Scope s
@GetMapping("foo")String foo(@SessionAttribute("foo")String foo) {
// equals to sessiong.getAttribute("foo")}
@GetMapping("bar")String bar(@RequestAttribute("bar")String bar) {
// equals to request.getAttribute("bar")}
Spring 4.3
@SessionAttribute/@RequestAttributefor access to session/request attributes
Spring Boot 1.4•Banner Update•Test Improvements•Spring Framework 4.3 Support•Misc
https://github.com/spring-‐‑‒projects/spring-‐‑‒boot/wiki/Spring-‐‑‒Boot-‐‑‒1.4-‐‑‒Release-‐‑‒Notes
Miscellaneous• Spring Boot 1.4• Startup error improvements• Couchbase 2.0 / Neo4J Support•@JsonComponent• Spring Security 4.1• Spring Data Hopper and so on...
• Spring Framework 4.3• Java Config supports constructor injection• Programmatic resolution of dependencies• Cache abstraction refinements• Built-‐‑‒in support for HTTP HEAD and OPTIONS• Caffeine Support• OkHttp3 Support and so on...
Enjoy Spring 4.3 / Boot 1.4 !!
Spring 5.0•A new framework generation for 2017+•5.0 M1 July 2016•5.0 RC1 December 2016
from Keynote @ Spring IO 2016
Spring 5.0•Major baseline upgrade•JDK 8+, Servlet 3.0+, JMS 2.0+, JPA 2.1+, JUnit 5
•JDK 9, Jigsaw•HTTP/2•Reactive Architecture
from Keynote @ Spring IO 2016
Reactor•Yet Another Rx library on the JVM•Natively built on top of Reactive Streams•Developed by Pivotal•Non-‐‑‒blocking•Reactor Core provides lite Rx API•Flux for 0..N elements•Mono for 0..1 element
https://projectreactor.io/
Spring Reactive
• Embeds Reactor• Experimental project on Spring 5 reactive support• Runs on• Reactor Net• RxNetty• Undertow• Servlet 3.1 containers (Servlet is optional !!)
• Same programming model as Spring MVC•Will be merged to 5.x branch after 4.3 released
https://github.com/spring-‐‑‒projects/spring-‐‑‒reactive
Spring Reactive@RestControllerpublic class TodosController {
@GetMapping("todos")Flux<Todo> list() {return this.repository.list();
}
@PostMapping("todos")Mono<Void> create(@RequestBody Flux<Todo> stream) {return this.repository.insert(stream);
}} https://github.com/sdeleuze/spring-‐‑‒reactive-‐‑‒playground
Spring Web Reactive
@MVC
HTTPReactive Streams
Servlet 3.1 Reactor I/O RxNetty
from Keynote @ Spring IO 2016
from Keynote @ Spring IO 2016Boot Security Data Cloud Integration
Spring Cloud
Spring Cloud http://projects.spring.io/spring-‐‑‒cloud/
Spring Cloud provides•Service Discovery•API Gateway•Client-‐‑‒side Load Balancing•Config Server•Circuit Breakers•Distributed Tracing
Spring Cloud provides•Service Discovery•API Gateway•Client-‐‑‒side Load Balancing•Circuit Breakers•Distributed Configuration•Distributed Tracing
Eureka
Zuul Ribbon
Hystrix
Zipkin
Microservices with Spring Cloud
Go to Cloud Native
Cloud Native?•"Software designed to run and scale reliably and predictably on top of potentially unreliable cloud-‐‑‒based infrastructure"(Duncan C.E. Winn, Free O'Reilly Book: Intro to the Cloud Native Platform)
•Microservices is a part of Cloud Native
Cloud Native
Cloud Native
DevOps ContinuousDelivery
ContainersMicroservices
Continuous DeliveryRelease once every 6
monthsMore Bugs in production
Release early and oftenHigher Quality of Code
DevOpsNot my problem
Separate tools, varied incentives, opaque process
Shared responsibilityCommon incentives, tools, process
and culture
MicroservicesTightly coupled componentsSlow deployment cycles waiting on integrated tests teams
Loosely coupled componentsAutomated deploy without waiting
on individual components
Continuous DeliveryRelease once every 6
monthsMore Bugs in production
Release early and oftenHigher Quality of Code
DevOpsNot my problem
Separate tools, varied incentives, opaque process
Shared responsibilityCommon incentives, tools, process
and culture
MicroservicesTightly coupled componentsSlow deployment cycles waiting on integrated tests teams
Loosely coupled componentsAutomated deploy without waiting
on individual components
ArchitectureProcessCulture
Why Microservices?•Speed and Safety• They enable faster innovation.
Monolith
Service Oriented Architecture
Microserviceshttp://www.kennybastani.com/2016/04/event-‐‑‒sourcing-‐‑‒microservices-‐‑‒spring-‐‑‒cloud.html
Monolith to Microservices
Monolith to Microservices
Chotto-‐‑‒Matte
✋
Start from 12 Factors Apphttp://12factor.net/
I. CodebaseOne codebase tracked in SCM, many deploys
II. DependenciesExplicitly declare and isolate dependencies
III. ConfigurationStore config in theenvironment
VI. ProcessesExecute app as stateless processes
V. Build, Release, RunStrictly separate build and run stages
IV. Backing ServicesTreat backing services as attached resources
IX. DisposabilityMaximize robustnesswith fast startup andgraceful shutdown
VIII. ConcurrencyScale out via the process model
VII. Port bindingExport services via port binding
XII. Admin processesRun admin / mgmttasks as one-‐‑‒off processes
X. Dev/prod parityKeep dev, staging, prod as similar as possible
XI. LogsTreat logs as eventstreams
12 Factors App
Cloud Native Platform
Pivotal Cloud Foundry
http://pivotal.io/platform
12 FactorsApp
Auto Scaling
MultiTenancy
Container
4 Level HA
AutoHealing
Spring Cloud Services
Metrics
OAuth2 SSODocker
IaaSAgnostic
BackendServices
LoggingBlue/GreenDeployment
EasyInstallation
Spring Cloud Serviceshttp://docs.pivotal.io/spring-‐‑‒cloud-‐‑‒services/
• Netflix OSS-‐‑‒as-‐‑‒a-‐‑‒service in Pivotal Cloud Foundry
Microservices with Spring Cloud
Microservices with SCS
Remove boilerplate code, implement patterns
Application coordination boilerplate patterns
Application configuration boilerplate patterns
Enterprise application boilerplate patterns
Runtime Platform, Infrastructure Automation boilerplate patterns (provision, deploy, secure, log, data services, etc.)
CLOUD
DESKTOP
Spring Boot
Spring IO Platform
Pivotal Cloud Foundry
Spring Cloud
Microservice operation boilerplate patterns (ConfigServer, Service Discovery, Circuit Breaker)
SERVICES
Spring Cloud Services
Concourse CIhttps://concourse.ci
Concourse CI Overview
http://www.slideshare.net/gwennetourneau/concourseci-‐‑‒overview
How Pivotal make cycle of code seamless!!
DEMOdeploy https://github.com/metflix
More practical pipeline
https://github.com/making/concourse-‐‑‒ci-‐‑‒demo
More practical pipeline
https://github.com/making/concourse-‐‑‒ci-‐‑‒demo
Pivotal Cloud Foundry for Local Developmenthttps://docs.pivotal.io/pcf-‐‑‒dev/
Tutorials• http://pivotal.io/platform/pcf-‐‑‒tutorials/getting-‐‑‒started-‐‑‒with-‐‑‒pivotal-‐‑‒cloud-‐‑‒foundry• https://github.com/Pivotal-‐‑‒Japan/cf-‐‑‒workshop• https://github.com/Pivotal-‐‑‒Japan/cloud-‐‑‒native-‐‑‒workshop
EBooks (Free!)
• http://pivotal.io/platform/migrating-‐‑‒to-‐‑‒cloud-‐‑‒native-‐‑‒application-‐‑‒architectures-‐‑‒ebook• http://pivotal.io/cloud-‐‑‒foundry-‐‑‒the-‐‑‒cloud-‐‑‒native-‐‑‒platform• http://pivotal.io/beyond-‐‑‒the-‐‑‒twelve-‐‑‒factor-‐‑‒app
Summary• Spring 4.3, Spring Boot 1.4 Jun 2016• DI・MVC Improvements, Composed Annotations ...• Image Banner, Test Improvements, ...
• Spring 5.0 • JDK 8+, JDK9, HTTP/2, Reactive
• Cloud Native• Microservices
• Speed & Safety• Independently Deployable
• Continuous Delivery• Concourse CI
• Containers, DevOps• Cloud Foundry as a Cloud Native Platform
top related