All Projects → spring-guides → Getting Started Guides

spring-guides / Getting Started Guides

Licence: apache-2.0
Getting Started Guide template :: The template for new guides and also the place to request them.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Getting Started Guides

Spring Best Practices
spring 最佳实践 Demo案例
Stars: ✭ 333 (-6.72%)
Mutual labels:  spring-boot
Spring Cloud Bus
Spring Cloud event bus
Stars: ✭ 342 (-4.2%)
Mutual labels:  spring-boot
Iot push
基于netty+mqtt3.1.1+springboot+jdk8 实现的 mqtt 服务端跟客户端
Stars: ✭ 353 (-1.12%)
Mutual labels:  spring-boot
Spring Jpa Best Practices
spring-jpa best practices
Stars: ✭ 332 (-7%)
Mutual labels:  spring-boot
Jhipster Kotlin
Kotlin based JHipster
Stars: ✭ 339 (-5.04%)
Mutual labels:  spring-boot
Dokit
基于 Spring Boot2、 Jpa、 Spring Security、JWT、redis、Vue的前后端分离的后台管理系统开发平台, 用户管理、菜单管理、角色管理、字典管理、权限控制的方式为RBAC,操作日志、异常日志、接口限流、项目支持数据权限管理,支持一键生成前后端代码(支持在线预览及打包下载),支持前端菜单动态路由 可一键部署服务器应用,数据库。系统中活跃用户状态监控,监视当前系统CPU、内存、磁盘、堆栈等相关信息,基于Element UI在线表单设计及生成Vue代码。
Stars: ✭ 348 (-2.52%)
Mutual labels:  spring-boot
Clusterdevicecontrolplatform
Java & Vue.js 全栈「集群设备管理云平台『后端部分』」,使用 Spring Boot、Netty 搭建 TCP 服务器与上万设备的集群通信,基于 JavaFX 的 GUI 应用程序模拟上万台设备的行为,并可对服务器进行压力测试。
Stars: ✭ 330 (-7.56%)
Mutual labels:  spring-boot
Springboot Mybatis
A REST back-end framework, integrated by Spring Boot, MyBatis and Spring Security OAuth
Stars: ✭ 359 (+0.56%)
Mutual labels:  spring-boot
Java server
基于SpringMVC+spring+Mybatis的校园o2o电商项目的后台和管理平台
Stars: ✭ 341 (-4.48%)
Mutual labels:  spring-boot
Azure Spring Boot
Spring Boot Starters for Azure services
Stars: ✭ 352 (-1.4%)
Mutual labels:  spring-boot
System Series
📚 服务端开发实践与工程架构,服务端基础篇 | 微服务与云原生篇 | Spring 篇 | Node.js 篇 | DevOps 篇 | 信息安全与渗透测试篇
Stars: ✭ 336 (-5.88%)
Mutual labels:  spring-boot
Spring Boot Microservices Series
Code for SpringBoot MicroServices Blog Series
Stars: ✭ 338 (-5.32%)
Mutual labels:  spring-boot
Springboot
springboot 和一些主流框架的整合的各个基本demo
Stars: ✭ 350 (-1.96%)
Mutual labels:  spring-boot
Spring Boot Demo
spring boot demo 是一个Spring Boot、Spring Cloud的项目示例,根据市场主流的后端技术,共集成了30+个demo,未来将持续更新。该项目包含helloworld(快速入门)、web(ssh项目快速搭建)、aop(切面编程)、data-redis(redis缓存)、quartz(集群任务实现)、shiro(权限管理)、oauth2(四种认证模式)、shign(接口参数防篡改重放)、encoder(用户密码设计)、actuator(服务监控)、cloud-config(配置中心)、cloud-gateway(服务网关)等模块
Stars: ✭ 323 (-9.52%)
Mutual labels:  spring-boot
Romaniancoderexamples
Java / SpringBoot / Angular examples for the Romanian Coder YouTube channel
Stars: ✭ 353 (-1.12%)
Mutual labels:  spring-boot
Novel Cloud
小说精品屋-微服务版是基于小说精品屋-plus构建的Spring Cloud 微服务技术栈学习型小说项目,致力于原创文学阅读与写作,提供了爬虫工具用于开发过程中测试数据的采集。采用了时下流行的Spring Boot 2 、Spring Cloud Hoxton、 MyBatis3DynamicSql、Sharding-Jdbc、Redis、RabbitMq、Elasticsearch、Docker等流行技术,集成了Nacos注册中心/配置中心、Spring Cloud Gateway网关、Spring Boot Admin监控中心、ELK分布式日志分析等基础服务。前端计划使用Vue开发。
Stars: ✭ 329 (-7.84%)
Mutual labels:  spring-boot
Ibase4j Springboot
Spring,SpringBoot,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。
Stars: ✭ 348 (-2.52%)
Mutual labels:  spring-boot
Jwt Angular Spring
JSON Web Token example that integrates both a Spring backend with an AngularJS frontend.
Stars: ✭ 358 (+0.28%)
Mutual labels:  spring-boot
Db Scheduler
Persistent cluster-friendly scheduler for Java
Stars: ✭ 352 (-1.4%)
Mutual labels:  spring-boot
Thymeleaf Spring
Thymeleaf integration module for Spring
Stars: ✭ 349 (-2.24%)
Mutual labels:  spring-boot

:spring_version: current :spring_boot_version: 2.2.2.RELEASE :Controller: https://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/stereotype/Controller.html :DispatcherServlet: https://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/web/servlet/DispatcherServlet.html :SpringApplication: https://docs.spring.io/spring-boot/docs/{spring_boot_version}/api/org/springframework/boot/SpringApplication.html :ResponseBody: https://docs.spring.io/spring/docs/{spring_version}/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html :toc: :icons: font :source-highlighter: prettify :project_id: gs-spring-cloud-circuitbreaker This guide walks you through the process of applying circuit breakers to potentially-failing method calls using Spring Cloud Circuit Breaker.

== What you'll build

You'll build a microservice application that uses the http://martinfowler.com/bliki/CircuitBreaker.html[Circuit Breaker pattern] to gracefully degrade functionality when a method call fails. Use of the Circuit Breaker pattern can allow a microservice to continue operating when a related service fails, preventing the failure from cascading and giving the failing service time to recover.

== What you'll need

:java_version: 1.8 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/prereq_editor_jdk_buildtools.adoc[]

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/how_to_complete_this_guide.adoc[]

[[reveal-gradle]] [.reveal-gradle] == Build with Gradle

[[scratch]] [.use-gradle] == Build with Gradle

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_system_intro.adoc[]

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_directory_structure_hello.adoc[]

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_both_builds.adoc[]

bookstore/build.gradle // AsciiDoc source formatting doesn't support groovy, so using java instead [source,java]

include::https://raw.githubusercontent.com/spring-guides/{project_id}/master/initial/bookstore/build.gradle[]

reading/build.gradle // AsciiDoc source formatting doesn't support groovy, so using java instead [source,java]

include::https://raw.githubusercontent.com/spring-guides/{project_id}/master/initial/reading/build.gradle[]

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/spring-boot-gradle-plugin.adoc[]

[[reveal-maven]] [.reveal-maven] == Build with Maven

[[use-maven]] [.use-maven] == Build with Maven

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_system_intro_maven.adoc[]

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_directory_structure_hello.adoc[]

bookstore/pom.xml [source,xml]

include::https://raw.githubusercontent.com/spring-guides/{project_id}/master/initial/bookstore/pom.xml[]

reading/pom.xml [source,xml]

include::https://raw.githubusercontent.com/spring-guides/{project_id}/master/initial/reading/pom.xml[]

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/spring-boot-maven-plugin.adoc[]

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/hide-show-sts.adoc[]

[[initial]] == Set up a server microservice application

The Bookstore service will have a single endpoint. It will be accessible at /recommended, and will (for simplicity) return a Mono of String recommended reading list.

Edit our main class, in BookstoreApplication.java. It should look like this:

bookstore/src/main/java/hello/BookstoreApplication.java [source,java,tabsize=2]

include::complete/bookstore/src/main/java/hello/BookstoreApplication.java[]

The @RestController annotation marks BookstoreApplication as a controller class, like @Controller does, and also ensures that @RequestMapping methods in this class will behave as though annotated with @ResponseBody. That is, the return values of @RequestMapping methods in this class will be automatically converted appropriately from their original types and will be written directly to the response body.

We're going to run this application locally alongside a client service application, so in src/main/resources/application.properties, set server.port so that the Bookstore service won't conflict with the client when we get that running.

bookstore/src/main/resources/application.properties [source,properties]

include::complete/bookstore/src/main/resources/application.properties[]

== Set up a client microservice application

The Reading application will be our front-end (as it were) to the Bookstore application. We'll be able to view our reading list there at /to-read, and that reading list will be retrieved from the Bookstore service application.

reading/src/main/java/hello/ReadingApplication.java [source,java,tabsize=2]

package hello;

import reactor.core.publisher.Mono;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.reactive.function.client.WebClient;

@RestController @SpringBootApplication public class ReadingApplication {

@RequestMapping("/to-read")
public Mono<String> toRead() {
  return WebClient.builder().build()
  .get().uri("http://localhost:8090/recommended").retrieve()
  .bodyToMono(String.class);

}

public static void main(String[] args) { SpringApplication.run(ReadingApplication.class, args); } }

To get the list from Bookstore, we're using Spring's WebClient class. WebClient makes an HTTP GET request to the Bookstore service's URL as we provide it and then returns the result as a Mono of String. (For more information on using Spring to consume a RESTful service using WebClient, see the https://spring.io/guides/gs/reactive-rest-service/[Building a Reactive RESTful Web Service] guide.)

Add the server.port property to src/main/resources/application.properties:

reading/src/main/resources/application.properties [source,properties]

include::complete/reading/src/main/resources/application.properties[]

We now can access, in a browser, the /to-read endpoint on our Reading application, and see our reading list. Yet since we rely on the Bookstore application, if anything happens to it, or if Reading is simply unable to access Bookstore, we'll have no list and our users will get a nasty HTTP 500 error message.

== Apply The Circuit Breaker Pattern Spring Cloud's Circuit Breaker library provides an implementation of the Circuit Breaker pattern: when we wrap a method call in a circuit breaker, Spring Cloud Circuit Breaker watches for failing calls to that method, and if failures build up to a threshold, Spring Cloud Circuit Breaker opens the circuit so that subsequent calls automatically fail. While the circuit is open, Spring Cloud Circuit Breaker redirects calls to the method, and they’re passed on to our specified fallback method.

Spring Cloud Circuit Breaker supports many different circuit breaker implementations including, Resilience4J, Hystrix, Sentinal, and Spring Retry. In this guide we will use the Resilience4J implementation. To use this implementation we just need to add spring-cloud-starter-circuitbreaker-reactor-resilience4j to our application's classpath.

reading/pom.xml [source,xml]

include::complete/reading/pom.xml[]

reading/build.gradle [source,groovy]

include::complete/reading/build.gradle[]

Spring Cloud Circuit Breaker provides an interface called ReactiveCircuitBreakerFactory which we can use to create new circuit breakers for our application. An implementation of this interface will be auto-configured based on the starter that is on your application's classpath. Lets create a new service that uses this interface to make API calls to the Bookstore application

reading/src/main/java/hello/BookService.java [source,java]

include::complete/reading/src/main/java/hello/BookService.java[]

The ReactiveCircuitBreakerFactory has a single method called create we can use to create new circuit breakers. Once we have our circuit breaker all we have to do is call run. Run takes a Mono or Flux and an optional Function. The optional Function parameter acts as our fallback if anything goes wrong. In our sample here the fallback will just return a Mono containing the String Cloud Native Java (O'Reilly).

With our new service in place, we can update the code in ReadingApplication to use this new service.

reading/src/main/java/hello/ReadingApplication.java [source,java]

include::complete/reading/src/main/java/hello/ReadingApplication.java[]

== Try it out

Run both the Bookstore service and the Reading service, and then open a browser to the Reading service, at localhost:8080/to-read. You should see the complete recommended reading list:


Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)

Now shut down the Bookstore application. Our list source is gone, but thanks to Hystrix and Spring Cloud Netflix, we have a reliable abbreviated list to stand in the gap; you should see:


Cloud Native Java (O'Reilly)

== Summary

Congratulations! You've just developed a Spring application that uses the Circuit Breaker pattern to protect against cascading failures and to provide fallback behavior for potentially failing calls.

include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/footer.adoc[]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].