Gradle創建Spring Boot項目——1配置
第一步,創建項目並配製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);
}
}
到這裏所有的配置就完成了。
最後更新:2017-06-23 23:35:28