In this fully-loaded session we will give you an update on all things Spring. We will talk about the latest features in Spring Framework 4.2 which was released this summer, and also provide an outlook to what is coming with Spring 5 in 2016.
Next, Spring Boot 1.3 is on the horizon and adds many new features. We will go over those and explain how Spring Boot helps you build production-ready Spring applications.
And then we add Spring Cloud to the mix and explain the various modules.
3. Spring Data
3
Core Jpa Gemfire REST
KeyValue MongoDB Redis
Solr
Foundational Store Modules Web Apis
Core
Modules
Community
Modules
Jpa Gemfire
MongoDB Redis
5. Spring 4.2
• @AliasFor
• Hibernate5 Support
• JMS Improvements
• Support for Money, Currency and TimeZone
(Formatter / ConversionService)
5
6. • 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
7. 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')")
8. JUnit Rules
• SpringClassRule & SpringMethodRule
• Can be used with any JUnit runner
8
@RunWith(Parameterized.class)
@ContextConfiguration
public class ParameterizedSpringRuleTests {
@ClassRule
public static final SpringClassRule SPRING_CLASS_RULE
= new SpringClassRule();
@Rule
public final SpringMethodRule springMethodRule
= new SpringMethodRule();
9. 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();
}
10. Spring Web
• SimpUserRegistry
• CompletableFuture (Java 8)
• OkHTTP Integration with RestTemplate
• ScriptTemplateView
• JavaScript view templating, Nashorn (JDK 8)
10
11. HTTP Caching
• CacheControl builder
• A builder for creating "Cache-Control" HTTP
response headers.
11
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/public-resources/")
.setCacheControl(CacheControl.maxAge(1,TimeUnit.HOURS)
.cachePublic());
}
}
12. 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
13. 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) { … }
}
14. 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
22. Boot 1.3
• Spring 4.2 and Spring Security 4.0
• OAuth2 Support
• Colorful Ascii Art Banners
22
23. Boot 1.3
• Fully executable JARs and service support
• Start as Unix/Linux services
• init.d
• systemd
23
$ ./myapp.jar
24. 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
25. 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
26. 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
27. 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
32. Migrating to 1.3
• https://github.com/spring-projects/spring-boot/
wiki/Spring-Boot-1.3-Release-Notes
• Several properties changed
• Dependency updates
32
33. 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
37. 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
38. • Service Discovery
• Circuit Breaker
• Client Side Load Balancer
• Router and Filter
• Spring Cloud Stream + Data Flow
• Distributed tracing
38
Spring Cloud