51
The Spring Update Roy Clarkson | Glenn Renfro | Gunnar Hillert

The Spring Update

Embed Size (px)

Citation preview

Page 1: The Spring Update

The Spring UpdateRoy Clarkson | Glenn Renfro | Gunnar Hillert

Page 2: The Spring Update

Spring

2

Page 3: The Spring Update

Spring Data

3

Core Jpa Gemfire REST

KeyValue MongoDB Redis

Solr

Foundational Store Modules Web Apis

Core Modules

Community Modules

ElasticSearch Cassandra

Couchbase Neo4j

Page 4: The Spring Update

Spring Social

4

Page 5: The Spring Update

Spring 4.2

• @AliasFor

• Hibernate5 Support

• JMS Improvements

• Support for Money, Currency and TimeZone (Formatter / ConversionService)

5

Page 6: The Spring Update

• Used to declare aliases between attributes within an annotation

• e.g., locations and value in @ContextConfiguration, or path and value in @RequestMapping

• Used in composed annotations

@AliasFor

6

https://github.com/sbrannen/spring-composed

Page 7: The Spring Update

Spring 4.2 Testing• Support for HtmlUnit incl. Selenium Webdriver

integration

• @Commit instead @Rollback(false)

• ContextCache is public Api

• @Sql

7

@Test@Sql(statements = "DROP TABLE user IF EXISTS")@Sql(scripts = “/test-schema.sql", statements = "INSERT INTO user VALUES ('Dilbert')")

Page 8: The Spring Update

JUnit Rules • SpringClassRule & SpringMethodRule

• Can be used with any JUnit runner

8

@RunWith(Parameterized.class)@ContextConfigurationpublic class ParameterizedSpringRuleTests {@ClassRule

public static final SpringClassRule SPRING_CLASS_RULE = new SpringClassRule();@Rule

public final SpringMethodRule springMethodRule = new SpringMethodRule();

Page 9: The Spring Update

Embedded DBs• Unique Names for Embedded Databases

• Why? Recreating an embedded database within the same JVM doesn’t actually create anything: a second attempt simply connects to the existing one.

9

@Bean

public DataSource dataSource() { return new EmbeddedDatabaseBuilder() .generateUniqueName(true) .addScript("schema.sql") .addScript("user_data.sql") .build();}

Page 10: The Spring Update

Spring Web

• SimpUserRegistry

• CompletableFuture (Java 8)

• OkHTTP Integration with RestTemplate

• ScriptTemplateView

• JavaScript view templating, Nashorn (JDK 8)

10

Page 11: The Spring Update

HTTP Caching• CacheControl builder

• A builder for creating "Cache-Control" HTTP response headers.

11

@Configuration@EnableWebMvcpublic class WebConfig extends WebMvcConfigurerAdapter {

@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**") .addResourceLocations("/public-resources/") .setCacheControl(CacheControl.maxAge(1,TimeUnit.HOURS)

.cachePublic()); }}

Page 12: The Spring Update

HTTP Caching

12

@RequestMapping("/book/{id}")public ResponseEntity<Book> showBook(@PathVariable Long id) {

Book book = findBook(id); String version = book.getVersion();

return ResponseEntity .ok() .cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)) .eTag(version) // lastModified is also available .body(book);}

• Usage in Controllers

Page 13: The Spring Update

Spring Web• Cross-origin resource sharing (CORS)

13

@CrossOrigin(maxAge = 3600)@RestController@RequestMapping("/account")public class AccountController {

@CrossOrigin(origins = "http://domain2.com")@RequestMapping("/{id}")public Account retrieve(@PathVariable Long id) { … }

@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")public void remove(@PathVariable Long id) { … }

}

Page 14: The Spring Update

Async

• Spring 3.2 Async Request Handling

• Spring 4.0 WebSocket Messaging (SockJS + Stomp)

• Spring 4.2 HttpStreaming

• Spring 4.2 Server-Sent Events (SSE)

• Spring 4.2 Direct Streaming

14

Page 15: The Spring Update

Server-Sent Events

15

@RequestMapping("/metrics")public SseEmitter subscribeMetrics() { SseEmitter emitter = new SseEmitter();

// Save emitter for further usage return emitter;}

Page 16: The Spring Update

Spring 4.3

• Refinements

• A richer set of convenience annotations (pre-composed)

16

Page 17: The Spring Update

Spring 5• Q4 2016

• Comprehensive JDK 9 support

• Java 8 baseline

• Servlet 3.0+

• HTTP/2

• Reactive support

17

https://github.com/spring-projects/spring-reactive

Page 18: The Spring Update

Spring Boot 1.3

18

Pathway to #NoXML

Page 19: The Spring Update

0

450000

900000

1350000

1800000

July 14 Sep 14 Nov 14 Jan 15 Mar 15 May 15 Jul 15

Spring Boot Adoption

19

Page 20: The Spring Update

• https://spring.io/blog/2013/03/04/spring-at-china-scale-alibaba-group-alipay-taobao-and-tmall/

20

“AliExpress is the beginning of a new effort to re-architect Taobao.com and Alipay.com for microservices and cloud native, built on Spring Boot and Spring Cloud.”

- Leijuan, Principal Engineer, AliExpress

Page 21: The Spring Update

21

Page 22: The Spring Update

Boot 1.3• Spring 4.2 and Spring Security 4.0

• OAuth2 Support

• Colorful Ascii Art Banners

22

Page 23: The Spring Update

Boot 1.3

• Fully executable JARs and service support

• Start as Unix/Linux services

• init.d

• systemd

23

$ ./myapp.jar

Page 24: The Spring Update

Boot 1.3• Additional Health Indicators

• Actuator Metrics (Java 8)

• New actuator endpoints - e.g. /logfile

• Hypermedia for MVC actuator endpoints

• Actuator docs endpoint

24

Page 25: The Spring Update

Boot 1.3• Spring Session Autoconfiguration

• Persistent sessions (Opt-in)

• Ant Support

• Support for @WebServlet, @WebFilter, and @WebListener

• When using an embedded servlet container, automatic registration of @WebServlet, @WebFilter, and @WebListener annotated classes can now be enabled using @ServletComponentScan.

25

Page 26: The Spring Update

Logging• Logback

• Spring Profile specific Configuration

• Use Environment Properties in Logback’

• logback-spring.xml

• Log4J 1.x deprecated

26

https://blogs.apache.org/foundation/entry/apache_logging_services_project_announces

Page 27: The Spring Update

Boot Developer Tools• Property Defaults

• Automatic application restarts

• Remote development support

27

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-devtools

Page 28: The Spring Update

Boot Developer Tools• LiveReload support

• Install LiveReload browser plugin

• Bowser Refresh Button

28

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>

Page 29: The Spring Update

Caching• @EnableCaching

• Auto-configuration now for:

29

JSR 107Guava

Page 30: The Spring Update

Boot and SPAs

• Web jars - /webjars/**

• /static, /public, /resources, /META-INF/resources

• Creating modular jars

30

Page 31: The Spring Update

Demo

31

https://github.com/ghillert/botanic-ng

Page 32: The Spring Update

Migrating to 1.3• https://github.com/spring-projects/spring-boot/

wiki/Spring-Boot-1.3-Release-Notes

• Several properties changed

• Dependency updates

32

Page 33: The Spring Update

JSPs and Web.xml

• JSP limitations for über-Jars

• Servlet 3.0 to the rescue

• /META-INF/resources/WEB-INF/jsp

• Possible to Eliminate Web.xml

• TomcatEmbeddedServletContainerFactory

33

Page 34: The Spring Update

34

Page 35: The Spring Update

Demo

35

https://github.com/devnexus/devnexus-site

JSPs with

Page 36: The Spring Update

Spring Initializr• http://start.spring.io

36

Page 37: The Spring Update

Tooling - STS• Spring Boot YML properties editor

• with code completion

• Improved support for Cloud Foundry

• Support for Spring Boot DevTools

• Attach Java debugger to CF deployed apps

• Spring Boot Dashboard

37

Page 38: The Spring Update

• Service Discovery

• Circuit Breaker

• Client Side Load Balancer

• Router and Filter

• Spring Cloud Stream + Data Flow

• Distributed tracing

38

Spring Cloud

Page 39: The Spring Update

39

Eureka

Hystrix

Spring Cloud

Consul

Page 40: The Spring Update

12 factor app principles

40

Codebase Depen-dencies Config Backing

Services

Build Release

RunProcesses Port

Binding Concurrency

Disposa-bility

Dev/Prod Parity Logs Admin

Processes

http://12factor.net

Page 41: The Spring Update

Demo

41

https://github.com/springone2gx2015/vehicle-fleet-demo

Page 42: The Spring Update

Demo

42

Page 43: The Spring Update

Spring & Cloud Native

43

Core Boot Connectors Service

Registry Config Server

Circuit Breaker

Ops Dev

Page 44: The Spring Update

44

#fundJUnit

• Pivotal sponsoring JUnit

• Developer Sponsor

• 6 weeks of senior developer

• Campaign Sponsor

• €5000 donation

Page 45: The Spring Update

Books

45

http://pivotal.io/platform/migrating-to-

cloud-native-application-

architectures-ebook

Page 46: The Spring Update

Books

46

Page 47: The Spring Update

Books

47

Page 48: The Spring Update

48

Page 49: The Spring Update

• Full-Day Workshop

• Several Spring Speakers

49

Delivering Cloud Native Applications with Spring

and Cloud Foundry

Page 50: The Spring Update

Questions?

50

Page 51: The Spring Update

Thank You!

51

Credits: Justin Blake, nathanbui, Bohdan Burmich, David Waschbüsch, Gabriele Malaspina, Creative Stall, Aha-Soft

https://github.com/ghillert/ajug-spring-update

@ghillert @royclarkson@cppwfs

@springcentral