Hello Spring Boot

I have installed Spring STS on a Windows box, and to check that everything is OK, I am writing the usual Hello World program. I have already did it for a previous version and stored the source code on GitHub.

However, it is more fun to do it again from scratch.

From the menu File, I select the wizard to create a New Spring Starter Project.

Then I fill the required fields to specify the project name and a few extra information. I am going to keep much of the proposed default values.
Next page, I keep the default Spring Boot Version, currently 1.4.3, and I add just one extra dependency, Web.
Clicking on Next, we can check what the wizard is doing for us, using the Spring Initializr web site passing the expected parameters. Otherwise, we can simply Finish, and let STS do the work for us.

A few seconds later, I have my new shiny helloSpring project. I open the project POM (remember that I accepted the default project type, Maven), and I am not surprised to see it reflects the selections I have chosen by the wizard.
In the Spring Elements sections, there is a new bean, whose name is based on the name I gave to the project, in this case HelloSpringApplication. Let's have a look at its source code.
The class is in the dd.manny.hello package, as I asked in the wizard, and has been annotated as @SpringBootApplication. It contains a main() method that calls SpringApplication.run() passing as parameters the class itself and the args passed to the application. We expect that on startup Spring sees this is the booting class, and uses its main to call the SpringApplication run() method.

To run my hello application, I now go to the Spring Boot Dashboard. By default, you should find this view on the bottom left in your STS window. If missing, you could get it back from Window - Show View
In the Boot Dashboard Local list I see my application, I select it, and now I can start the associated process. In the console window I can see the resulting logging.
Among the messages, I see a couple of them issued from my class, dd.manny.hello.HelloSpringApplication:
Starting HelloSpringApplication on a555 with PID 8552 
Started HelloSpringApplication in 1.348 seconds (JVM running for 1.995)
Good. The application worked fine.

No comments:

Post a Comment