Springboot Introduction (i)--ready to use out of the box

Source: Internet
Author: User
Tags spring initializr

this article fromNetEase Cloud CommunityWhat is Spring boot?

In essence, spring boot is a collection of libraries, a framework for rapid application based on the principle of "convention over configuration". In essence, it's still spring, which saves us a lot of boilerplate configuration, allowing us to focus more on the development of application functionality.

Spring Boot Essentials

Springboot brings a lot of magic into the development of spring applications, the most important of which is the following four cores

    • Automatic configuration: For common application features, Springboot automatically provides relevant configuration to reduce time spent on boilerplate configurations

    • Start-Up dependency: Specify feature-based dependencies to reduce dependency complexity with greater granularity of dependencies

    • Command-line interface: This is an optional feature of Springboot, which allows you to write code to complete your application without the need for a traditional project build

    • Actuator: Lets you drill down into the running Springboot application to find out what

Start from spring

In order to embody the advantages of springboot, let's take a look at what we need to do if we use spring to develop a simple Hello World Web application:

    • A project structure, with a maven or gradle artifact file that contains the necessary dependencies, at the very least, with spring MVC and servlet API dependencies

    • A Web. xml file (or a Webapplicationinitializer implementation) that declares the spring Dispatcherservlet

    • A spring configuration with spring MVC enabled

    • A controller class that responds to HTTP requests with "Hello World"

    • A Web application server for deploying applications, such as Tomcat

It is possible to see that the above series of things only write the controller is related to the HelloWorld function, although the modern IDE can also help us to simplify some of the steps, but the spring-related configuration even from another project copy can not escape this step.

Let's take a look at what happens with spring boot.

Spring boot is available out of the box

When was the last time you pushed your door in a supermarket or a large retail store? Most large stores have automatic doors with inductive features, although all doors allow you to enter the building, but automatic doors do not need to be pushed and pulled. Similarly, many public toilets are equipped with automatic sense taps and automatic induction paper towels. Although there is no supermarket automatic door so popular, but these facilities also do not have too many requirements for you, can be very convenient to water and paper towels. I bet you can come up with countless examples to prove that devices make modern life more automated, not more of a hindrance.

Here's an example of how spring boot is out of the box. Still the Hello World Web project, let's look at how to create it with Intelij idea. Click on the idea's file-new-project ... and select Spring Initializr in the left tab to see the following interface.

Using the default Https://start.spring.io, this will connect to the network, querying the current available version of spring boot and the list of components. (The current time is 2.0.0.RELEASE of spring boot)

next-Input project information-next, came to choose the starting dependency interface, as follows:

For a simple Hello World Web project, just tick the web (I'll check the thymeleaf here and see it at the far right of the window). In this interface you can see the large number of start dependencies that spring boot provides for us. The web we've chosen will inject all of the web-related dependencies, eliminating the time we have to configure our own dependencies.

One more click the next project will be completed, waiting for download related maven dependencies (it may take a long time for the first time) and idea to create an index.

After the creation is complete, the project structure looks like this:

is a common MAVEN project structure, more specifically spring boot for us automatically generated 2 files, application.properties and Blogdemoapplication.java.

Application.properties is the SPIRNG boot default configuration file, when the period is an empty file, now ignore the following will be said in detail.

Blogdemoapplication.java is the spring boot auto-generated startup class. With this class, the project is now a Web project that can be started, and although there are no controllers, we can still try to access the default port 8080. If idea does not automatically create a startup configuration, you can add it yourself to run/debug configurations. Select Spring Boot on Add and select the auto-generated startup class in the "Main class" of the box on the right, as follows:

When you click Run, Access port 8080 will get the Spring boot default error page:

Then we can develop our function--hello world.

@[email protected] ("/demo") public class Helloworldcontroller {@RequestMapping ("/hello") @ResponseBody public Str    ing hello () {return "Hello"; }}

Very simple a controller, and finally start the project again, has been able to happy Hello!

Summary

To recap, get rid of the verbose introduction, the actual operation only point point, enter the project name, and then write a controller to complete a Hello world. As if back to the beginning of the Java era, then or Eclipse, is also point point, enter the project name, and then write a Main method console output a hello. The steps are similar, but this time it is already a Web project with a lot of spring features.

Related reading: Springboot introduction (i)--out of the box

Springboot Introduction (ii)--Start dependence

Springboot Introduction (iii)--Import class parsing

Springboot Introduction (iv)--automatic configuration

Springboot Introduction (V)--Custom configuration

NetEase Cloud New User package: Https://www.163yun.com/gift

This article from the NetEase cloud community, by the author King authorized release.

Springboot Introduction (i)--ready to use out of the box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.