IDEA builds spring Boot+mybatis

Source: Internet
Author: User
Tags connection pooling spring initializr

Spring boot is not the general cool Ah, also use what SSM, hurriedly change!

Environments to prepare for:

Idea 2017.2

jdk1.8.0_144

Maven 3.5.0

Please configure idea with Maven and JDK in advance, and the project is relatively new.

Steps:

First, use idea to create a new spring INITIALIZR project

Tick as needed, check out a few of the most commonly used ones here!

Click Finish to build the project! The first use may take a long time.

Second, the configuration

You can see the following directory structure when you are finished.

Where application.properties is a configuration file, however we recommend using the YML format configuration, so delete it and create a new application.yml, Application-dev.yml, Application-prod.yml.

Where APPLICATION.YML is the global configuration, APPLICATION-DEV.YML is the configuration used for the development environment APPLICATION-PROD.YML the configuration used for the build environment.

Application-dev.yml

Spring:  Profiles:
#表示所用配置文件为application-dev.yml Active:dev datasource: driver-class-name:com.mysql.jdbc.driver Url:jdbc:mysql://xxxxxx:3306/chatrobot?useunicode=true&characterencoding=utf8&useSSL =false username:xxxxx password:xxxxx Tomcat: initialsize:1 min-idle:1 Max-idle:20 max-wait:60000 timebetweenevictionrunsmillis:60000 minevictableidletimemillis:30000 validationquery:select 1 testwhileidle:true testonborrow:false testonreturn:falselogging: File:logs/demo.log

Configuration files are configured here, as well as database and database connection pools, and log output to files, and connection pooling uses the officially recommended Tomcat connection pool.

Application-dev.yml

Server:  port:8080

Configure the development environment here to use port 8080.

Application-prod.yml

Server:  port:443  SSL:    key-store:classpath:xxx.jks    key-store-password:xxx    Keystoretype:jks    keyalias:xxx

Here the production environment is configured to use port 443 and the Https,keyalias is configured as the certificate alias.

Demoapplication.java

 PackageCom.demo;ImportOrg.mybatis.spring.annotation.MapperScan;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;Importorg.springframework.scheduling.annotation.EnableScheduling, @SpringBootApplication @mapperscan ("Com.demo.dao") @EnableScheduling Public classDemoApplication { Public Static voidMain (string[] args) {Springapplication.run (demoapplication.class, args); }}

This is the program entrance, the development of the direct operation can be.

@MapperScan ("Com.demo.dao"), scan the MyBatis Mapper under the DAO package.

@EnableScheduling the Spring Schedule timed task is enabled, it can be removed.

The configuration is probably so much, very simple, other uses and SSM is no different, of course, can also configure actuator to monitor the application, quite powerful.

Third, the release

Use the command line to enter the project directory to execute the following command.

MVN Clean Package

The default and recommended packaging method is jar, where Tomcat is integrated and, of course, can be modified to war.

There is a data directory location problem with the package jar, and my workaround is to put the data directory under System.getproperty ("User.dir").

The runtime executes the following command directly.

Java-jar Demo.jar

You can use the following command on Linux to run in the background.

Nohup Java-jar Demo.jar >/dev/null2>&1 &

Idea builds spring Boot+mybatis

Related Article

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.