Spring Boot Preliminary

Source: Internet
Author: User
Tags connection pooling system log

Spring Boot IntroductionSpring Boot is a new framework provided by the Pivotal team designed to simplify the initial setup and development of new Spring applications.
    • The framework uses a specific approach to configuration, which eliminates the need for developers to define a boilerplate configuration
Usage Scenarios
    • Web back-end projects can be developed with spring boot
Spring boot Positioning is an entry-level microservices development FrameworkFeatures:Simple CodingSimple ConfigurationLow Learning costsSimple Deploymentbuilt-in containers1. Tools for new projectsTools: ideaHow to create: Idea,spring Tool Suite,https://start.spring.io/ The first two tools can be built directly, the following is the official spring Web site, this is to build a basic spring boot project, and then need to download and unzipa plugin needs to be installed in Eclipse: STS2. Create a project using ideaCreate a demorun a simple programThere is no configuration file specified when the default port for the project is 8080, and no second level of the project directory3, the project configuration fileSpring Boot supports a multi-environment configuration, and profile naming is the application-environment name. YMLthen specify which environment to use in the main configuration fileLoad Resources4. Integrated MyBatisAdd DependencyTo configure database connection information in a configuration fileConfigure connection PoolingConfigure MyBatisstarting class and scanning annotations for mapper files5. Scheduled Tasksto add annotations on the startup class that open a timed taskuse the time expression directly above the task you want to perform to

Turn on timed tasks
@EnableScheduling

6. Asynchronous Invocationadding annotations on the startup class that turn on asynchronous execution

To turn on asynchronous invocation methods
@EnableAsync

7. Integrated RedisAdd DependencyPerfecting configuration FilesExecute Code8. Custom log Fileslogback-spring.xml A custom log file9. Packing Methodmaven packaged commands can be run as jar packages directlyfight a war bag1 The jar for the modified Pom file is war2 Adding dependencies3 Modifying the master boot file to inherit the Springbootservletinitializer class and overriding the method
    • @Override protected Springapplicationbuilder Configure (Springapplicationbuilder builder) {return builder.sources ( Springdemoapplication.class); }
the port that is accessed after the war package is the Tomcat port, and the project name is also the name of the war packageCustom log files: Logback-spring.xml
<?xml version= "1.0" encoding= "UTF-8"? ><configuration scan= "true" > <!--appName--<property NA Me= "AppName" value= "Mei-app-web-demo"/> <!--%m output information,%p log level,%t thread name,%d date, full name of the%c class,,,,--> <appender name= "CO Nsole "class= "Ch.qos.logback.core.ConsoleAppender" > <encoder> <!--<pattern>%d%p (%file:%line\)-% m%n</pattern>--> <!--formatted output:%d: Represents the date%thread: Represents the thread name%-5level: The level displays 5 character widths from the left%msg: Log message%n: is a newline character --<pattern>%black ([${appname}])%red (%-12 (%d{yyyy-mm-dd HH:mm:ss. SSS}))%green (|-%-5level)%highlight ([%thread]%c [%l])-| %msg%N</pattern> <charset>utf-8</charset> </encoder> </appender> <conte    xtname>${appname}</contextname> <!--absolute path to log storage--<property name= "LogPath" value= "F:/logs"/> <!--set the system log directory--<property name= "Appdir" value= "${appname}"/> <!--Description:1, log level and file log records are graded, and levels correspond to log file names, and different levels of log information are logged to different log files for example: Error level logged to Log_error_xxx.log or Log_erro R.log (the file is the log file of the current record), and Log_error_xxx.log as the archive log, log files by date, the same day, if the log file size is equal to or greater than 2M, press 0,1, 2... Order names such as log-level-2013-12-21.0. Log other levels of logging are the same. 2, file path If you are developing, testing, and running the project in Eclipse, go to the installation path of Eclipse to find the logs folder to the relative path :/logs. If deployed under Tomcat, in the logs file under Tomcat3, Appender fileerror corresponding to the error level, file name with log-error-xxx.log form named Filewarn corresponds to warn level, file name with log-warn-xxx.log Form name FileInfo corresponding info level, file name with log-info-xxx.log form name filedebug corresponds to debug level, file name with log-debug-xxx.log Form name console outputs log information to control for easy development and test use-<!--logger, date scrolling error---<appender name= "Fileerror"class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <!--the path and file name of the log file that is being recorded--<file>${logpath }/${appdir}/log_error.log</file> <!--The logger's scrolling strategy, by date, by size--<rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <!--the path to the archived log file, for example today is 2013-12-21st logs, the currently written log file path is specified by the file node, which can be set to a different path to the file specified by a path, thereby placing the current log file or archive log file in a different directory. and-12-21 of log files are specified by Filenamepattern. %D{YYYY-MM-DD} Specifies the date format,%i the specified index--<filenamepattern>${logpath}/${appdir}/error/log-error-%d{yyyy-mm-dd}.% I.log</filenamepattern> <!--In addition to logging, the log file must not exceed 2M, if more than 2M, the log file will start at index 0, named log files, such as log-error-2013-12-21.0.log-<timebasedfilenamingandtriggeringpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" > <maxFileSize>2MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!--append logging--&L T;append>true</append> <!--log file format-<encoderclass= "Ch.qos.logback.classic.encoder.PatternLayoutEncoder" > <pattern>[${appname}]===%d{yyyy-mm-dd HH:mm:ss . SSS}%-5level%logger line:%-3l-%msg%n</pattern> <charset>utf-8</charset> </encod er> <!--This log file only records the error level--<filterclass= "Ch.qos.logback.classic.filter.LevelFilter" > <level>error</level> &LT;ONMATCH&GT;ACC ept</onmatch> <onMismatch>DENY</onMismatch> </filter> </appender> &L t;! --Logger, date scrolling record warn--<appender name= "Filewarn"class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <!--the path and file name of the log file that is being recorded--<file>${logpath }/${appdir}/log_warn.log</file> <!--The logger's scrolling strategy, by date, by size--<rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <!--the path to the archived log file, for example today is 2013-12-21st logs, the currently written log file path is specified by the file node, which can be set to a different path to the file specified by a path, thereby placing the current log file or archive log file in a different directory. and-12-21 of log files are specified by Filenamepattern. %D{YYYY-MM-DD} Specifies the date format,%i the specified index--<filenamepattern>${logpath}/${appdir}/warn/log-warn-%d{yyyy-mm-dd}.%i. Log</filenamepattern> <!--In addition to logging, the log file must not exceed 2M, if more than 2M, the log file will start at index 0, named log files, such as log-error-2013-12-21.0.log-<timebasedfilenamingandtriggeringpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" > <maxFileSize>2MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!--append logging--&L T;append>true</append> <!--log file format-<encoderclass= "Ch.qos.logback.classic.encoder.PatternLayoutEncoder" > <pattern>[${appname}]===%d{yyyy-mm-dd HH:mm:ss . SSS}%-5level%logger line:%-3l-%msg%n</pattern> <charset>utf-8</charset> </encod er> <!--This log file only records warn levels--<filterclass= "Ch.qos.logback.classic.filter.LevelFilter" > <level>warn</level> <onmatch>acce pt</onmatch> <onMismatch>DENY</onMismatch> </filter> </appender> &lt ;! --Logger, date scrolling info---<appender name= "FileInfo"class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <!--the path and file name of the log file that is being recorded--<file>${logpath }/${appdir}/log_info.log</file> <!--The logger's scrolling strategy, by date, by size--<rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <!--the path to the archived log file, for example today is 2013-12-21st logs, the currently written log file path is specified by the file node, which can be set to a different path to the file specified by a path, thereby placing the current log file or archive log file in a different directory. and-12-21 of log files are specified by Filenamepattern. %D{YYYY-MM-DD} Specifies the date format,%i the specified index--<filenamepattern>${logpath}/${appdir}/info/log-info-%d{yyyy-mm-dd}.%i. Log</filenamepattern> <!--In addition to logging, the log file must not exceed 2M, if more than 2M, the log file will start at index 0, named log files, such as log-error-2013-12-21.0.log-<timebasedfilenamingandtriggeringpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" > <maxFileSize>2MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!--append logging--&L T;append>true</append> <!--log file format-<encoderclass= "Ch.qos.logback.classic.encoder.PatternLayoutEncoder" > <pattern>[${appname}]===%d{yyyy-mm-dd HH:mm:ss . SSS}%-5level%logger line:%-3l-%msg%n</pattern> <charset>utf-8</charset> </encod er> <!--This log file only records the info level--<filterclass= "Ch.qos.logback.classic.filter.LevelFilter" > <level>info</level> <onmatch>acce pt</onmatch> <onMismatch>DENY</onMismatch> </filter> </appender> &lt ;! --Logger, date scrolling record debug---<appender name= "Filedebug"class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <!--the path and file name of the log file that is being recorded--<file>${logpath }/${appdir}/log_debug.log</file> <!--The logger's scrolling strategy, by date, by size--<rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <!--the path to the archived log file, for example today is 2013-12-21st logs, the currently written log file path is specified by the file node, which can be set to a different path to the file specified by a path, thereby placing the current log file or archive log file in a different directory. and-12-21 of log files are specified by Filenamepattern. %D{YYYY-MM-DD} Specifies the date format,%i the specified index--<filenamepattern>${logpath}/${appdir}/debug/log-debug-%d{yyyy-mm-dd}.% I.log</filenamepattern> <!--In addition to logging, the log file must not exceed 2M, if more than 2M, the log file will start at index 0, named log files, such as log-error-2013-12-21.0.log-<timebasedfilenamingandtriggeringpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" > <maxFileSize>2MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <!--append logging--&L T;append>true</append> <!--log file format-<encoderclass= "Ch.qos.logback.classic.encoder.PatternLayoutEncoder" > <pattern>[${appname}]===%d{yyyy-mm-dd HH:mm:ss . SSS}%-5level%logger line:%-3l-%msg%n</pattern> <charset>utf-8</charset> </encod er> <!--This log file only records the debug level--<filterclass= "Ch.qos.logback.classic.filter.LevelFilter" > <level>debug</level> &LT;ONMATCH&GT;ACC ept</onmatch> <onMismatch>DENY</onMismatch> </filter> </appender> &L t;! --<logger name= "Com.minlia" level= "DEBUG"/>--> <!--<logger name= "Org.springframework.data.mybatis" Level= "DEBUG"/> <logger name= "org.springframework.aop.aspectj" level= "ERROR"/> <logger name= "javax.acti Vation "level=" WARN "/> <logger name=" Javax.mail "level=" WARN "/> <logger name=" Javax.xml.bind "level=" WAR  N "/> <logger name=" Ch.qos.logback "level=" INFO "/> <logger name=" Com.sun "level=" WARN "/> <logger Name= "Com.zaxxer" level= "WARN"/> <logger name= "Io.undertow" level= "WARN"/> <logger name= "Net.sf.ehcache "Level=" WARN "/> <logger name=" Org.apache "level=" WARN "/> <logger name=" Org.hibernate.validator "level=" WARN "/> <logger naMe= "Org.hibernate" level= "WARN"/> <logger name= "org.hibernate.ejb.HibernatePersistence" level= "OFF"/> < Logger name= "Org.springframework.web" level= "INFO"/> <logger name= "org.springframework.security" level= "WARN" /> <logger name= "Org.springframework.cache" level= "WARN"/> <logger name= "org.thymeleaf" level= "WARN"/&gt    ; <logger name= "Sun.rmi" level= "WARN"/> <logger name= "liquibase" level= "WARN"/> <logger name= "sun.rmi.t Ransport "level=" WARN "/> <logger name=" jdbc.connection "level=" ERROR "/> <logger name=" Jdbc.resultset "le vel= "Error"/> <logger name= "jdbc.resultsettable" level= "INFO"/> <logger name= "jdbc.audit" level= "error"/ > <logger name= "jdbc.sqltiming" level= "ERROR"/> <logger name= "jdbc.sqlonly" level= "INFO"/>--> & lt;! --Log configuration for different environments--<springprofile name= "Dev" > <root level= "DEBUG" > <!--<appender-r EF ref= "Fileerror"/>--> <!--<appender-ref ref= "Filewarn"/>--> <!--<appender-ref ref= "FileInfo"/&        gt;--> <!--<appender-ref ref= "Filedebug"/>--> <appender-ref ref= "CONSOLE"/>            </root> </springProfile> <springprofile name= "Test" > <root level= "DEBUG" >            <!--<appender-ref ref= "Fileerror"/>--> <!--<appender-ref ref= "Filewarn"/>--> <appender-ref ref= "FileInfo"/> <appender-ref ref= "Filedebug"/> <appender-ref ref = "CONSOLE"/> </root> </springProfile> <springprofile name= "prod" > <root level= "DEBUG" > <!--<appender-ref ref= "Fileerror"/>--> <!--<appender-ref ref= "Filewarn "/>--> <!--<appender-ref ref=" FileInfo "/>--> <!--<appender-ref ref=" Filedeb          UG "/>-->  <appender-ref ref= "CONSOLE"/> </root> </springProfile></configuration> 

Spring Boot Preliminary

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.