第一步,创建项目并配制build.gradle文件
通过Intellij IDEA新建一个Gradle项目
在build.gradle文件中添加项目配制,执行一次Refresh all Gradle Projects
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.springframework.boot:spring-boot-starter"
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-amqp'
compile 'org.springframework.boot:spring-boot-starter-integration'
compile 'org.springframework.integration:spring-integration-file:4.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'mysql:mysql-connector-java'
compile 'com.google.code.gson:gson:2.8.0'
compile "io.springfox:springfox-swagger-ui:2.2.2"
compile "io.springfox:springfox-swagger2:2.2.2"
testCompile("org.springframework.boot:spring-boot-starter-test")
}
————————————————————————————————————
—————————————————————————————————————
第二步,配制application.yml文件
server:
port: 8081
context-path: /api/
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.1.108:3306/test2?characterEncoding=utf8&useSSL=false
username: cm
password: cm8888
initialSize: 5
minIdle: 5
maxActive: 20
jpa:
hibernate:
ddl-auto: update
naming:
strategy: org.hibernate.cfg.ImprovedNamingStrategy
show-sql: true
database: mysql
logging:
file: springboot.log
第三步,添加Application.java文件
package com.wuti;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
/**
* Created by wtrover on 2017/6/23.
*/
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Autowired
ApplicationContext context;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}