Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Have You Seen Spring Lately?

Josh Long
January 20, 2014

Have You Seen Spring Lately?

It's been an amazing year for Spring! 2013 saw the Spring family join Pivotal where - along with Cloud Foundry and our data driven technologies (the Pivotal HD Hadoop distribution, the GemFire data grid, and the RabbitMQ message broker) - Spring supports today's application workloads and profiles. Today's Spring embraces Java 8, Scala, Groovy, provides a best-in-class REST stack, supports the open web, mobile applications, big-data applications and batch workloads. Today's Spring is easy to get started with, easy to learn, and embraces conventions over configuration. Today's Spring is part of the Spring.IO platform. Today's Spring is...Pivotal. Join Spring developer advocate Josh Long as he re-introduces you to today's Spring, a Spring you may not have seen yet.

Josh Long

January 20, 2014
Tweet

More Decks by Josh Long

Other Decks in Technology

Transcript

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

    View Slide

  2. 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

    View Slide

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

    View Slide

  4. 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

    View Slide

  5. 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

    View Slide

  6. 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

    View Slide

  7. 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++

    View Slide

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

    View Slide

  9. 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);

    View Slide

  10. 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!

    View Slide

  11. 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;
    }

    View Slide

  12. 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() {
    ...
    }

    View Slide

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

    View Slide

  14. 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

    View Slide

  15. 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;
    }
    }

    View Slide

  16. 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
    }
    }

    View Slide

  17. 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)

    View Slide