27
Spring Boot – framework for micro services Jakub Kubryński [email protected] @jkubrynski

Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński [email protected]

  • Upload
    dinhbao

  • View
    261

  • Download
    9

Embed Size (px)

Citation preview

Page 1: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Spring Boot – framework for micro services

Jakub Kubryń[email protected]

@jkubrynski

Page 2: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

whoami

Page 3: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

History

• 1999 J2EE 1.2

• 2001 xDoclet 1.0

• 2004 Spring Framework 1.0● Injection● POJO oriented● AOP & transactions

• 2006 Java EE 5

Page 4: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

'Classic' way

• hundreds of thousands LOC

• thousands of tests ... or not

• hundreds of issues in jira

• and a lot of design patterns

... lava flow, big ball of mud, orgy, yo-yo

Page 5: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

'Classic' way

Page 6: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Micro way

• Single responsibility

• Loosely coupled

• Reliable

• Small, light

Page 7: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Micro way

Page 8: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Hard?

• Versioning

• Integration testing

• Boilerplate bootstrap code

Page 9: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

History

• 1999 J2EE 1.2

• 2001 xDoclet 1.0

• 2004 Spring Framework 1.0● Injection● POJO oriented● AOP & transactions

• 2006 Java EE 5

• 2013 Spring Boot!

Page 10: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Focus

source: spring.io

Page 11: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Revolution

@RestController@EnableAutoConfigurationpublic class HelloWorld {

@RequestMapping("/") public String helloWorld() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(HelloWorld.class, args); }

}

Page 12: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Key features

• Stand-alone Spring applications

• Embedded Tomcat or Jetty

• Starter dependencies

• Automatic configuration

• Production-ready environment

• No code generation / no XML config

Page 13: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Blocks

• SpringApplication

• @EnableAutoConfiguration

• @ConditionalOnClass

• @ConditionalOnBean

• @ConditionalOnExpression

Page 14: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Sample auto-configuration

@Configuration

@ConditionalOnClass({ MBeanExporter.class })

@ConditionalOnMissingBean({ MBeanExporter.class })

@ConditionalOnExpression("${spring.jmx.enabled:true}")

public class JmxAutoConfiguration {

...

}

Page 15: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Starters

• spring-boot-starter

• spring-boot-starter-web

• spring-boot-starter-test

• spring-boot-starter-actuator

Page 16: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Starters

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

Page 17: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Production ready

• Monitoring endpoints● /health● /info● /metrics● /mappings

• JMX / SSH

• Auditing

Page 18: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Properties

@ConfigurationProperties(prefix=”mail”)

public class MailProperties {

private InetAddress serverAddress;

private Resource template;

}

mail.serverAddress : 84.123.456.32

mail.template : classpath:mail.vm

Page 19: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Profiles

• spring.profiles.active = production,mysql

• configuration per profile:● application-production.properties● conference-test.properties

Page 20: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Logging

• log4j

• logback

• java.util.Logging

Page 21: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Security

• spring-boot-starter-security

• @SecurityAutoConfiguration

• @SecurityProperties● security.requireSsl = true

Page 22: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

WAR

public class WebInit extends SpringBootServletInitializer {

@Override

protected SpringApplicationBuilder

configure(SpringApplicationBuilder application) {

return application.sources(SampleApplication.class);

}

}

Page 23: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

Tests

@SpringApplicationConfiguration(classes =

Application.class)

@ContextConfiguration(classes = Application,

loader = SpringApplicationContextLoader)

@IntegrationTest

Page 24: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

It's Spring

Page 25: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

How it helps?

● Dramatically reduces boilerplate code● Enables polyglot● Simplifies integration testing● Simplifies environment maintenance

Page 26: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

You have questions

I (probably) have answers

Page 27: Spring Boot – framework for micro servicesbottega.com.pl/pdf/materialy/SpringBootServices.pdf · Spring Boot – framework for micro services Jakub Kubryński jk@devskiller.com

END! THANK YOU