Share
Embed
Transcript
31 slides
-
Spring Boot Main @EnableAutoConfiguration @ComponentScan public class Main { public
static void main(String[] args) { SpringApplication.run(Main.class, args); } } Enable Spring Boot Configuration e.g. Web environment etc Scan for Spring annotations e.g. @Component @Configuration etc In this package and all sub packages Start application e.g. Tomcat, Spring web environment etc @SpringBootApplication = @ComponentScan+ @EnableAutoConfiguration+ @Configuration -
Spring Boot: Maven pom.xml <project ...> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.1.RELEASE</version>
</parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ... </dependencies> Configuration inherits from parent Sets versions for dependencies Add all needed libs for a web app Many starters available -
Spring Boot: Maven pom.xml ... <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugins> </build> </project> Makes WAR / JAR executable Support mvn spring-boot:run to run the app -
Spring Boot § Build much easier § Supports Gradle &
Ant, too § Not limited to simple application § Can add any other library § Application much easier to test, debug etc § Simple code -
Spring Data JPA § Makes implementation of repositories trivial §
Just provide an interface § Needs JPA infrastructure of course -
Spring Data JPA Repository public interface CustomerRepository extends JpaRepository<Customer, Long>
{ List<Customer> findByName(String name); } Defines all basic CRUD (Create, Read, Update, Delete) operations Implementation created by naming convention Add Spring Boot Starter Data JPA No further configuration Without Spring Boot <repositories base-package="de.project" /> or @EnableJpaRepositories("de.project") -
Behind the Scenes § DataSource for HSQL created § JPA
infrastructure created § Thymeleaf infrastructure created § How does it work? § Convention over configuration -
Spring Boot § Creates sensible infrastructure defaults § i.e. DataSource
if HSQL is on the classpath § Done by *AutoConfiguration classes -
Spring Boot Starter amqp aop batch data-jpa data-mongodb data-rest integration
jdbc mobile redis security test web websocket actuator remote-shell jetty tomcat log4j logback data-solr data-elasticsearch data-gemfire groovy-templates freemarker thymeleaf mustache undertow velocity social-facebook social-linkedin social-twitter -
Dev § Turn Around § Thymeleaf Templates can be changed
on the fly § …same with class files § Spring Loaded makes reloading more powerful -
CRaSH Shell § Ever ssh’d into your application? § Enter
CRaSH § External library integrated into Spring Boot § Alternative approach to operations -
Actuator § Provide information about the application § Via http
/ JSON § Can be evaluated by monitoring tools etc. § Another alternative approach to monitoring -
Deploy § Just package everything in an executable JAR §
…or a WAR § Based on Maven or Gradle § Build in configuration (YAML, properties etc.) -
What‘s next? Spring Cloud § Technologies for Micro Services §
E.g. Configuration § Resilience § Netflix stack § Cloud Bus § Cloud Security § Based on Spring Boot -
Conclusion § Easy to start § Can add libraries and
features as needed § Dev: Quick turn around § Ops: Integrated monitoring § Ops: Easy deployment § Didn’t show Groovy support -
Spring Boot & Microservices § Simplifies deployment § Standardizes Ops
interface § Simplify creating REST / web applications