Software 152 Liu Hao John
First, the concept:
In essence, 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 Starting the Entrance
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
* Log files 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