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

Intro à Spring Boot

Brian Clozel
February 05, 2016

Intro à Spring Boot

Devfest Paris 2016

Brian Clozel

February 05, 2016
Tweet

More Decks by Brian Clozel

Other Decks in Programming

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Intro to Spring Boot Stéphane Nicoll, Pivotal inc. @snicoll Brian Clozel, Pivotal inc. @brianclozel
  2. Adding a simple REST Controller @RestController public class HomeController {

    @RequestMapping("/") public String home() { return "Hello GDG DevFest!"; } }
  3. Spring Boot starters <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId>

    </dependency> § Adding here spring-data-jpa (interact with a JPA datastore) § and spring-data-rest (expose hypermedia resources) § Starters bring recommended dependencies and trigger autoconfiguration
  4. Writing an Hypermedia repository @Repository public interface SpeakerRepository extends CrudRepository<Speaker,

    Long> { @RestResource(path = "by-twitter") Speaker findByTwitter(@Param("id") String twitter); Collection<Speaker> findByLastName(String lastName); }
  5. In-Memory Authentication with Spring Security @Configuration static class SecurityConfig extends

    GlobalAuthenticationConfigurerAdapter { @Override public void init(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("hero").password("hero").roles("HERO", "USER").and() .withUser("user").password("user").roles("USER"); } }