Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ include::complete/src/main/java/com/example/testingrestdocs/HomeController.java[

== Run the Application

The Spring Initializr creates a `main` class that you can use to launch the application.
The following listing (from
The Spring Initializr creates a `{YourProjectName}Application` class with a `main` method
that you can use to launch the application. The following listing (from
`src/main/java/com/example/testingrestdocs/TestingRestdocsApplication.java`) shows the
application class that the Spring Initializr created:

Expand Down Expand Up @@ -93,7 +93,8 @@ application. Did you notice that there is not a single line of XML? There is no
file, either. This web application is 100% pure Java and you did not have to deal with
configuring any plumbing or infrastructure. Spring Boot handles all of that for you.

Logging output is displayed. The service should be up and running within a few seconds.
Run main(). Logging output is displayed and the service should be running within a few
seconds.

== Test the Application

Expand All @@ -105,13 +106,17 @@ part of the tests by using Spring REST Docs.

The first thing you can do is write a simple sanity check test that fails if the
application context cannot start. To do so, add Spring Test and Spring REST Docs as
dependencies to your project, in the test scope. The following listing shows what to add
if you use Maven:
dependencies to your project, in the test scope.

=== Maven

If you use Maven, the following listing shows what to add to the `<dependencies>`
section of `pom.xml`:

====
[source,xml]
----
include::complete/pom.xml[tag=test]
include::complete/pom.xml[tag=restdocs-dependency]
----
====

Expand All @@ -124,12 +129,14 @@ include::complete/pom.xml[]
----
====

The following example shows what to add if you use Gradle:
=== Gradle

If you use Gradle, add the following line to the `dependencies` section of your `build.gradle` file.

====
[source,groovy]
----
include::complete/build.gradle[tag=test]
include::complete/build.gradle[tag=restdocs-dependency]
----
====

Expand All @@ -142,7 +149,7 @@ include::complete/build.gradle[]
----
====

NOTE: You can ignore the comments in the build files. They are there to let us pick up
NOTE: You can ignore the `tag` comments in the build files. They are there to let us pick up
parts of the files for inclusion in this guide.

NOTE: You have included the `mockmvc` flavor of REST Docs, which uses Spring MockMvc to
Expand Down
2 changes: 2 additions & 0 deletions complete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
// tag::restdocs-dependency[]
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
// end::restdocs-dependency[]
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
Expand Down
8 changes: 3 additions & 5 deletions complete/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- tag::restdocs-dependency[] -->
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<!-- end::restdocs-dependency[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- We'll be using JUnit 5. Vintage is for JUnit 4 so we exclude it. -->
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
Expand Down
1 change: 1 addition & 0 deletions initial/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!-- We'll be using JUnit 5. Vintage is for JUnit 4 so we exclude it. -->
<exclusions>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excluding vintage seems like a good idea, but it doesn't come along with Spring Initializr. We just need to add a part in the tutorial to add this exclusion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better simply to omit this part - it shouldn't be necessary with latest version of Spring Boot.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the build.gradle needs to be fixed though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsyer, I've got a pull request aimed at starting this tutorial using the Spring Initializr (#11). That should fix any build concerns.

What do you think about that course of action?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this PR is redundant?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsyer, fixing the build in both places would be redundant, but no the PR is not redundant. This PR was mostly about fixing wording issues and adding clarifications; the other PR is focused on starting using Initializr.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but the exclusion is redundant still? I mean there’s something that needs fixing, I guess I don’t care which PR it happens in.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like after Spring Boot 2.4, the exclusion is redundant.

But, in this PR the version is still 2.3.2.RELEASE, so excluding vintage here is not redundant.

In #11, we move this tutorial to the latest version from Initialzr which is 2.4.1; but since we'll then be using the POM and other build files provided by Initializr, there's no problem there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was mistaken earlier when I said

We just need to add a part in the tutorial to add this exclusion.

Adding the exclusion isn't necessary with 2.4.1 and if you happen to be using an older version from Initialzr, it will exclude it if necessary.

<exclusion>
<groupId>org.junit.vintage</groupId>
Expand Down