Getting Started

We’re going to use the Spring Boot command-line interface (CLI) to bootstrap our first Spring Boot application (the CLI uses Spring Initializr under the covers). You are free to explore the different ways to do this if you’re not comfortable with the CLI. Alternatives include using Spring Initializr plug-ins for your favorite IDE or visiting the web version of Spring Initializr. The Spring Boot CLI can be installed a few different ways, including through package managers and by downloading it straight from the website. Check for instructions on installing the CLI most appropriate for your development environment.

Once you’ve installed the CLI tools, you should be able to check the version of Spring you have:

$ spring --version

Spring CLI v1.3.3.RELEASE

Getting Started

If you can see a version for your installation of the CLI, congrats! Now navigate to a directory where you want to host your examples from the book and run the following command:

spring init --build maven --groupId com.redhat.examples \

--version 1.0 --java-version 1.8 --dependencies web \

--name hola-springboot hola-springboot

After running this command, you should have a directory named hola-springboot with a complete Spring Boot application. If you run the command and end up with a demo.zip, then just unzip it and continue. Let’s take a quick look at what those command-line options are. --build

The build-management tool we want to use. maven or gradle are the two valid options at this time.

--groupId

The groupId to use in our maven coordinates for our pom.xml; unfortunately this does not properly extend to the Java package names that get created. These need to be modified by hand.

--version

The version of our application; will be used in later iterations, so set to 1.0.

--java-version

Allows us to specify the build compiler version for the JDK.

--dependencies

This is an interesting parameter; we can specify fully baked sets of dependencies for doing common types of development. For example, web will set up Spring MVC and embed an internal servlet engine (Tomcat by default; Jetty and Undertow as options). Other convenient dependency bundles/starters include jpa, security, and cassandra).

Now if you navigate to the hola-springboot directory, try running the following command:

$ mvn spring-boot:run

If everything boots up without any errors, you should see some logging similar to this:

2016-03-25 10:57:08.920 [main] AnnotationMBeanExporter

: Registering beans for JMX exposure on startup

2016-03-25 10:57:08.982 [main] TomcatEmbeddedServletContainer

: Tomcat started on port(s): 8080 (http)

2016-03-25 10:57:08.987 [main] HolaSpringbootApplication

: Started HolaSpringbootApplication in 1.0 seconds

(JVM running for 4.7)

Congrats! You have quickly gotten a Spring Boot application up and running! You can even navigate to http://localhost:8080in your browser and should see the following output:

This default error page is expected since our application doesn’t do anything yet! Let’s move on to the next section to add a REST endpoint to put together a hello-world use case!

results matching ""

    No results matching ""