官术网_书友最值得收藏!

Creating a reactive web application with Spring Initializr

In the last chapter, we took a quick tour through the Spring Initializr site at http://start.spring.io. Let's go back there and pick some basic ingredients to start building our social media site by picking the options needed as shown in the following screenshot:

As shown in the preceding screenshot, we've picked the following options:

  • Build system: Gradle
  • Spring Boot Version: 2.0
  • Group: com.greglturnquist.learningspringboot
  • Artifact: learning-spring-boot

For dependencies, we are going to use these:

  • Reactive Web: This pulls in Reactive Spring, something we'll explore here and through the rest of this book
  • Lombok: This is a tiny library that keeps Java interesting by handling getters, setters, toString, equals, hashCode, and more
  • Thymeleaf: This is not Boot's only supported template library, but a powerful one that includes reactive support as well as strict HTML compliance.

From here, we merely need to click on the Generate Project button and a zipped up project will be downloaded. Import it into our IDE, and we're ready to get rolling.

(We will add more dependencies to our project in later chapters.)

We won't list the entire Gradle build file generated by the site, but the dependencies are listed as follows:

    dependencies { 
      compile('org.springframework.boot:spring-boot-starter-webflux') 
      compile("org.springframework.boot:spring-boot-starter-thymeleaf") 
      compile('org.synchronoss.cloud:nio-multipart-parser:1.1.0') 
      compile('org.projectlombok:lombok') 
      testCompile('org.springframework.boot:spring-boot-starter-test') 
    } 

The following dependencies are included in the build file:

  • spring-boot-starter-webflux: This is the foundation for a Reactive Spring web applications
  • spring-boot-starter-thymeleaf: This brings in Thymeleaf's template engine
  • nio-multipart-parser: This is a third-party library from Synchronoss, which supports reactive multipart file uploads
  • lombok: This is a convenient library to create mutable and immutable value objects among other things
  • spring-boot-starter-test: This is a collection of test libraries including JUnit, Spring Boot Test, Mockito, AssertJ, JSONassert, and Hamcrest

What version of Spring Boot are we using? That can be spotted toward the top of build.gradle inside the buildscript fragment, as seen here:

    ext { 
      springBootVersion = '2.0.0.M5' 
    } 

The version is specified at the top to feed both spring-boot-gradle-plugin as well as in the dependencies.

The Gradle build additionally uses the Spring team's Dependency Management Gradle plugin (available here: https://github.com/spring-gradle-plugins/dependency-management-plugin), which includes several Maven-like dependency management features. It includes the ability to consume any Maven Bills of Materials (BOMs) while also handling direct and transitive dependencies.

With our build file in place, we can now dive into reactive programming.

主站蜘蛛池模板: 淳安县| 东兴市| 舞阳县| 揭西县| 石城县| 东乌珠穆沁旗| 东莞市| 平湖市| 周至县| 交口县| 志丹县| 兴山县| 勃利县| 鄯善县| 乐昌市| 宣化县| 遵义县| 金昌市| 新乡县| 丘北县| 雷波县| 沙坪坝区| 施秉县| 行唐县| 山阳县| 错那县| 南投县| 罗源县| 平武县| 东源县| 新竹县| 都兰县| 恩平市| 闽侯县| 图们市| 常宁市| 马关县| 靖安县| 凤台县| 西丰县| 石河子市|