Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
SPRING BOOT & 
MICROSERVICES 
@ladislavGazo 
gazo@seges.sk
huge application servers 
monolithic architecture 
long restarts 
no save-reload cycle 
wired to a set of dependencies
MICROSERVICES
PROS 
Each microservice is relatively small 
Easier for a developer to understand 
The IDE is faster making developers mor...
PROS 2 
Improved fault isolation 
In comparison, one misbehaving component of a monolithic 
architecture can bring down th...
BUT... 
(there is always at least one...) 
Developers must deal with the additional complexity of 
creating a distributed ...
... TACKLE WITH 
when to split to multiple microservices 
what should be inside one microservice 
single responsibility pr...
SPRING BOOT 
http://projects.spring.io/spring-boot/ 
opinionated way how to do modern applications
VERY EASY TO START 
<parent> 
<groupid>org.springframework.boot</groupid> 
<artifactid>spring-boot-starter-parent</artifac...
APP CODE 
package hello; 
import org.springframework.boot.*; 
import org.springframework.boot.autoconfigure.*; 
import org...
3 OPTIONS 
JRebel 
jHipster Reloader 
Spring Loaded
JHIPSTER RELOADER 
-javaagent:/home/user/.m2/repository/io/github/jhipster/loaded/agent/0.12/agent-0.12.jar 
<profiles> 
<...
INTERESTING DEPENDENCIES 
benefit of Spring Boot 
MVC 
data access 
templating 
security 
... 
... anything from the Sprin...
REST 
@RestController 
based on Spring MVC
TEMPLATING 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-thymeleaf</artifact...
SPRING SECURITY 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-security</arti...
MIGRATIONS 
<dependency> 
<groupId>org.flywaydb</groupId> 
<artifactId>flyway-core</artifactId> 
</dependency> 
migration ...
DATA ACCESS 
<dependency> 
<groupId>com.h2database</groupId> 
<artifactId>h2</artifactId> 
</dependency> 
<dependency> 
<g...
DATA ACCESS II. 
spring.datasource.url: jdbc:postgresql://localhost/mydb 
spring.datasource.username: myuser 
spring.datas...
CONFIGURATION 
driven mainly by: 
Spring Java Configuration 
Spring Annotations 
Spring Profiles 
simple YAML / properties...
CHERRY 
@Component 
@ConfigurationProperties(prefix="connection") 
public class ConnectionSettings { 
private String usern...
KONTANJERE
SKALA
GITER8 TEMPLATE 
https://github.com/lgazo/scala-boot.g8 
curl https://raw.githubusercontent.com/n8han/conscript/master/set...
QUESTIONS? 
@ladislavGazo 
gazo@seges.sk
THANK YOU... FOR... 
ATTENTION
Spring Boot and Microservices
Spring Boot and Microservices
Spring Boot and Microservices
Spring Boot and Microservices
Spring Boot and Microservices
Upcoming SlideShare
Loading in …5
×

Spring Boot and Microservices

How to start building microservices with Spring Boot

Spring Boot and Microservices

  1. 1. SPRING BOOT & MICROSERVICES @ladislavGazo gazo@seges.sk
  2. 2. huge application servers monolithic architecture long restarts no save-reload cycle wired to a set of dependencies
  3. 3. MICROSERVICES
  4. 4. PROS Each microservice is relatively small Easier for a developer to understand The IDE is faster making developers more productive The web container starts faster Easier to scale development. Each team can develop, deploy and scale their service independently of all of the other teams.
  5. 5. PROS 2 Improved fault isolation In comparison, one misbehaving component of a monolithic architecture can bring down the entire system. Each service can be developed and deployed independently Eliminates any long-term commitment to a technology stack
  6. 6. BUT... (there is always at least one...) Developers must deal with the additional complexity of creating a distributed system testing transactions use-cases span multiple microservices Deployment complexity In production Increased memory consumption
  7. 7. ... TACKLE WITH when to split to multiple microservices what should be inside one microservice single responsibility principle ... it is the art
  8. 8. SPRING BOOT http://projects.spring.io/spring-boot/ opinionated way how to do modern applications
  9. 9. VERY EASY TO START <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>1.1.8.RELEASE</version> </parent> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> </dependencies> ta-daaaa .... web app built :)
  10. 10. APP CODE package hello; import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; import org.springframework.stereotype.*; import org.springframework.web.bind.annotation.*; @Controller @EnableAutoConfiguration public class SampleController { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController.class, args); ... the beauty of autoconfiguration
  11. 11. 3 OPTIONS JRebel jHipster Reloader Spring Loaded
  12. 12. JHIPSTER RELOADER -javaagent:/home/user/.m2/repository/io/github/jhipster/loaded/agent/0.12/agent-0.12.jar <profiles> <profile> <id>reloaded</id> <dependencies> <dependency> <groupId>io.github.jhipster.loaded</groupId> <artifactId>agent</artifactId> <version>0.12</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> </dependencies> </profile> </profiles>
  13. 13. INTERESTING DEPENDENCIES benefit of Spring Boot MVC data access templating security ... ... anything from the Spring stack
  14. 14. REST @RestController based on Spring MVC
  15. 15. TEMPLATING <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> using Thymeleaf
  16. 16. SPRING SECURITY <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> @EnableWebMvcSecurity @EnableGlobalMethodSecurity http.authorizeRequests().antMatchers("/identity/login", "/page/**", "/client/**", "/user/**" http.csrf().disable(); http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); http.addFilterBefore(new AuthenticationTokenFilter(identityService), AnonymousAuthenticationFilter http.exceptionHandling().authenticationEntryPoint(new UnauthorizedEntryPoint());
  17. 17. MIGRATIONS <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> </dependency> migration files V1.1__init.sql V1.2__data.sql ...
  18. 18. DATA ACCESS <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> </dependency> autodetection of the driver
  19. 19. DATA ACCESS II. spring.datasource.url: jdbc:postgresql://localhost/mydb spring.datasource.username: myuser spring.datasource.password: mypass spring.datasource.driverClassName: org.postgresql.Driver <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>
  20. 20. CONFIGURATION driven mainly by: Spring Java Configuration Spring Annotations Spring Profiles simple YAML / properties file
  21. 21. CHERRY @Component @ConfigurationProperties(prefix="connection") public class ConnectionSettings { private String username; private InetAddress remoteAddress; // ... getters and setters } # application.yml connection: username: admin remoteAddress: 192.168.1.1
  22. 22. KONTANJERE
  23. 23. SKALA
  24. 24. GITER8 TEMPLATE https://github.com/lgazo/scala-boot.g8 curl https://raw.githubusercontent.com/n8han/conscript/master/setup.sh | sh # add to your path ~/bin cs n8han/giter8 g8 lgazo/scala-boot
  25. 25. QUESTIONS? @ladislavGazo gazo@seges.sk
  26. 26. THANK YOU... FOR... ATTENTION

×