Slide 1

Slide 1 text

Josh Long (⻰龙೭य़) @starbuxman joshlong.com [email protected] slideshare.net/joshlong github.com/joshlong http://spring.io 4 T W ! http://slideshare.net/joshlong

Slide 2

Slide 2 text

SPRING IS.. SPRING.IO WEB Controllers, REST, WebSocket INTEGRATION Channels, Adapters, Filters, Transformers BATCH Jobs, Steps, Readers, Writers BIG DATA Ingestion, Export, Orchestration, Hadoop DATA NON-RELATIONAL RELATIONAL CORE GROOVY FRAMEWORK SECURITY REACTOR GRAILS Full-stack, Web XD Stream, Taps, Jobs BOOT Bootable, Minimal, Ops-Ready

Slide 3

Slide 3 text

SPRING WORKS IN MANY LANGUAGES Spring loves the JVM: Java (5,6,7, and 8), Groovy, Scala, etc.

Slide 4

Slide 4 text

SPRING WORKS IN MANY LANGUAGES val applicationContext = new FunctionalConfigApplicationContext( classOf[ServiceConfiguration]) // ServiceConfiguration.scala class ServiceConfiguration extends FunctionalConfiguration { importClass(classOf[DataSourceConfiguration]) val dataSource : DataSource = getBean(“dataSource”) val jdbcTemplate = bean() { new JdbcTemplate( dataSource ) } val jdbcTransactionManager = bean(“txManager”) { new JdbcTransactionManager(dataSource) } } Scala

Slide 5

Slide 5 text

SPRING WORKS IN MANY LANGUAGES def bb = new BeanBuilder() bb.loadBeans("classpath:*SpringBeans.groovy") def applicationContext = bb.createApplicationContext() // MySpringBeans.groovy import o.sf.jdbc.core.JdbcTemplate import o.sf.jdbc.datasource.DataSourceTransactionManager beans { jdbcTemplate(JdbcTemplate) { dataSource = dataSource } transactionManager(DataSourceTransactionManager) { dataSource = dataSource } } Groovy

Slide 6

Slide 6 text

SPRING WORKS IN MANY LANGUAGES ApplicationContext applicationContext = new AnnotationConfigApplicationContext( ServiceConfiguration.class); // ServiceConfiguration.java @Configuration @ComponentScan @Import(DataSourceConfiguration.class) @EnableTransactionManagement class ServiceConfiguration { @Bean public JdbcTemplate jdbcTemplate(DataSource dataSource) throws Exception { return new JdbcTemplate( dataSource ); } @Bean public PlatformTransactionManager jdbcTransactionManager(DataSource dataSource){ return new JdbcTransactionManager (dataSource ); } } Java

Slide 7

Slide 7 text

SPRING WORKS IN MANY LANGUAGES Java 8 a quick note on Delayed again! from 09/2013 to as late as 03/2014! Meanwhile, even has lambas... ... C++

Slide 8

Slide 8 text

SPRING WORKS IN MANY LANGUAGES Java 8 a quick note on IDE Support: IntelliJ IDEA has had Java 8 support for over a year !

Slide 9

Slide 9 text

SPRING WORKS IN MANY LANGUAGES Java 8 a quick note on Spring 4.0 to be GA against Developer Preview by end of 2013. Method references are a great fit for Spring! JdbcTemplate jdbcTemplate; // method references private Customer map(ResultSet rs, int rowNum) throws SQLException { return new Customer( rs.getString("name"), rs.getInt("age") ); } // let it satisfy the `RowMapper` functional interface Customer customer = jdbcTemplate.queryForObject( "select name, age from customers ", this::map);

Slide 10

Slide 10 text

SPRING WORKS IN MANY LANGUAGES Java 8 a quick note on Spring 4.0 to be GA against Developer Preview by end of 2014. lambas are a great fit for Spring and Twitter!

Slide 11

Slide 11 text

SPRING WORKS IN MANY LANGUAGES Java 8 a quick note on JSR-310 - Date and Time // declarative date format import java.time.*; import org.springframework.format.annotation.*; public class Customer { @DateTimeFormat(iso=ISO.DATE) private LocalDate birthDate; @DateTimeFormat(pattern="M/d/yy h:mm") private LocalDateTime lastContact; }

Slide 12

Slide 12 text

SPRING WORKS IN MANY LANGUAGES Java 8 a quick note on Repeatable Annotations @Scheduled(cron = "0 0 12 * * ?") @Scheduled(cron = "0 0 18 * * ?") public void performTempFileCleanup() { ... }

Slide 13

Slide 13 text

WEBSOCKETS REST @RestController public class GreetingController{ @RequestMapping(“/greeting/{name}”) Greeting greet (@PathVariable String name) { return new Greeting( name) ; } }

Slide 14

Slide 14 text

REST DESIGN WITH SPRING of course, supports JSR 356 (javax.websocket.*) support. WebSockets delegating to implementations on app servers like GlassFish, Tomcat, and Jetty Supports Sock.js server, superset of WS. higher level STOMP supported on WS

Slide 15

Slide 15 text

WEBSOCKETS Handling Messages Over STOMP @Controller public class GreetingController { // Mapping based on "destination" header @MessageMapping("/greeting") @SendTo("/topic/greetings") public String greet(@MessageBody String greeting) { return "[" + getTimestamp() + "]: " + greeting; } }

Slide 16

Slide 16 text

WEBSOCKETS Configuring a STOMP WebSocket broker @Configuration @EnableWebSocketMessageBroker public class Config implements WebSocketMessageBrokerConfigurer { @Override public void registerStompEndpoints(StompEndpointRegistry r) { r.addEndpoint("/portfolio"); // WebSocket URL prefix } @Override public void configureMessageBroker(MessageBrokerConfigurer c) { c.enableSimpleBroker("/topic/"); // destination prefix } }

Slide 17

Slide 17 text

SPRING RUNS WELL ON JAVA EE 7 Spring works well in Java EE environments Supports Java EE 7: Date/Time API, JTA 1.2, JMS 2.0, JPA 2.1, Bean Validation 1.1, the new concurrency API in JSR-236, Servlet 3.1, and WebSockets (JSR 356) Even participated in a few JSRs: the websocket JSR (356) and the Batch JSR (352)