the spring update
Post on 25-Jan-2017
1.083 Views
Preview:
TRANSCRIPT
The Spring UpdateRoy Clarkson | Glenn Renfro | Gunnar Hillert
Spring
2
Spring Data
3
Core Jpa Gemfire REST
KeyValue MongoDB Redis
Solr
Foundational Store Modules Web Apis
Core Modules
Community Modules
ElasticSearch Cassandra
Couchbase Neo4j
Spring Social
4
Spring 4.2
• @AliasFor
• Hibernate5 Support
• JMS Improvements
• Support for Money, Currency and TimeZone (Formatter / ConversionService)
5
• 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
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')")
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();
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();}
Spring Web
• SimpUserRegistry
• CompletableFuture (Java 8)
• OkHTTP Integration with RestTemplate
• ScriptTemplateView
• JavaScript view templating, Nashorn (JDK 8)
10
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()); }}
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
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) { … }
}
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
Server-Sent Events
15
@RequestMapping("/metrics")public SseEmitter subscribeMetrics() { SseEmitter emitter = new SseEmitter();
// Save emitter for further usage return emitter;}
Spring 4.3
• Refinements
• A richer set of convenience annotations (pre-composed)
16
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
Spring Boot 1.3
18
Pathway to #NoXML
0
450000
900000
1350000
1800000
July 14 Sep 14 Nov 14 Jan 15 Mar 15 May 15 Jul 15
Spring Boot Adoption
19
• 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
21
Boot 1.3• Spring 4.2 and Spring Security 4.0
• OAuth2 Support
• Colorful Ascii Art Banners
22
Boot 1.3
• Fully executable JARs and service support
• Start as Unix/Linux services
• init.d
• systemd
23
$ ./myapp.jar
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
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
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
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
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>
Caching• @EnableCaching
• Auto-configuration now for:
29
JSR 107Guava
Boot and SPAs
• Web jars - /webjars/**
• /static, /public, /resources, /META-INF/resources
• Creating modular jars
30
Migrating to 1.3• https://github.com/spring-projects/spring-boot/
wiki/Spring-Boot-1.3-Release-Notes
• Several properties changed
• Dependency updates
32
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
34
Demo
35
https://github.com/devnexus/devnexus-site
JSPs with
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
• Service Discovery
• Circuit Breaker
• Client Side Load Balancer
• Router and Filter
• Spring Cloud Stream + Data Flow
• Distributed tracing
38
Spring Cloud
39
Eureka
Hystrix
Spring Cloud
Consul
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
Demo
41
https://github.com/springone2gx2015/vehicle-fleet-demo
Demo
42
Spring & Cloud Native
43
Core Boot Connectors Service
Registry Config Server
Circuit Breaker
Ops Dev
44
#fundJUnit
• Pivotal sponsoring JUnit
• Developer Sponsor
• 6 weeks of senior developer
• Campaign Sponsor
• €5000 donation
Books
45
http://pivotal.io/platform/migrating-to-
cloud-native-application-
architectures-ebook
Books
46
Books
47
48
• Full-Day Workshop
• Several Spring Speakers
49
Delivering Cloud Native Applications with Spring
and Cloud Foundry
Questions?
50
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
top related