Spring Boot Environment Setup

Source: Internet
Author: User

Software 152 Chen Zhuo

First, the concept:

from the most fundamental point, Spring Boot is a collection of libraries that can be used by any project's build system. For simplicity, the framework also provides a command-line interface that can be used to run and test the boot application. The release version of the framework, including the Integrated CLI (command line interface), can be downloaded and installed manually in the Spring warehouse. A simpler approach is to use the Groovy Environment Manager (Groovy Environment MANAGER,GVM), which handles the installation and management of the boot version. Boot and its CLI can be installed through the GVM command line GVM install Springboot. Install boot on OS X to use the Homebrew Package Manager. In order to complete the installation, first use the brew tap PIVOTAL/TAP to switch to the pivotal warehouse and then execute the Brew install Springboot command.

Second, the environment construction:

1. Engineering structure

using maven to build a common structure, because spring-boot is embedded in Tomcat, so the package only needs to be packaged as a jar to run directly, so the Web program is not built as before.

2. Introducing maven Dependencies

according to the official tutorial , the direct introduction of the parent can be used spring-boot to say goodbye to the previous spring tedious dependency configuration. Add the following configuration to the Pom.xml:

3. Write DEMO

3.1 entity class demoentity:

3.2 Controller Hellocontroller ( return JSON type ):

3.3 Boot entry

since it is a jar executor, a main function is required as the start-up entry and the following code is added to the Application.java:

3.4 Test Access

The Spring-boot is started on port 8080 by default and is directly accessible to the address:

4. Configure Logger

Log configuration for Spring-boot:

Never: Disable ansi-colored output (default)

DETECT: Check whether the terminal supports ANSI, and then use color output (recommended)

Always: Use ansi-colored format output, if the terminal is not supported, there will be a lot of interference information, not recommended to use

5. Using Logger

Spring-boot automatically introduces the use of SLF4J and Logback, and the use of logs does not need to be introduced into the package yourself. Modify the controller as follows:

6. Write log file

you need to configure the logging.file or logging.path Property in Application.properties:

Logging.file, the settings file can be either an absolute path or a relative path. such as:logging.file=my.log

Logging.path, sets the directory where the spring.log file is created and writes the contents of the log, such as:logging.path=/var/log

* The log file will be truncated at 10Mb , resulting in a new log file with the default level:ERROR,WARN, INFO *

7. Custom JSON parser

7.1 First introduced Fastjson dependency:

7.2 Build Webmessageconvert.java under the Conf package

8. The results show

Spring-boot when the message is launched, the configuration is successful

Spring Boot Environment Setup

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.