[SpringBoot學習]-IDEA建立Gradle多Module結構的SpringBoot專案
一、前言
上個月由於做了一個小的後臺系統,重新拾起Spring,發現之前搞的SSH、SpringMVC已經過時,新的SpringBoot整合了大部分的後端框架,俗稱Spring全家桶,還整合了tomcat更方便開發測試,故在寫專案的同時順便學習一下SpringBoot。由於本人目前主攻Android方向,所以對Intellj家族和Gradle更為喜歡,所有使用 IDEA、Gradle 、Gradle多Module 來開發SpringBoot,也使得Android開發習慣無縫遷移到SpringBoot開發上。相信IDEA、Gradle會是Web開發的主流環境。
二、建立專案
1、使用IEAD建立Gradle專案
2、輸入工程名,GroupId不用寫
3、使用gradle wrapper
4、建立名為app的主module
5、建立名為common的module
6、將根目錄settings.gradle 改為
include 'app'
include 'common'
7、將根目錄的build.gradle 改為
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
//AndroidStudio中開發springboot 使用apply plugin: 'org.springframework.boot'會有問題,必須新增一個AndroidModule才能正常。
//使用Intellj 開發純java工程或者 java web 更方便
//classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
###8、將app內的build.gradle改為
buildscript {
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
}
}
repositories {
jcenter()
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
maven { url "http://repo.maven.apache.org/maven2" }
}
apply plugin: 'org.springframework.boot'
apply plugin: 'java'
apply plugin: 'maven'
group = 'com.masonliu.cc'
version = '1.0.0'
description = """"""
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
sourceSets {
main {
//output.resourcesDir default is 'build/resources/main'
//output.classesDir default is 'build/classes/main'
//合併 classes 和 resources的輸出路徑,方便 直接執行 main方法時,在當前classpath下能找到 resources裡的配置檔案
output.resourcesDir = 'build/classes/main'
output.classesDir = 'build/classes/main'
}
}
configurations {
deployerJars
}
//https://stackoverflow.com/questions/36923288/how-to-run-bootrun-with-spring-profile-via-gradle-task
//def profiles = 'dev'
//bootRun {
// args = ["--spring.profiles.active=" + profiles]
//}
task pro << {
bootRun.systemProperty 'spring.profiles.active', 'pro'
}
task dev << {
bootRun.systemProperty 'spring.profiles.active', 'dev'
}
dependencies {
compile project(":common")
compile('org.xerial:sqlite-jdbc:3.8.11.2')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'1.5.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version:'1.5.4.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version:'4.3.9.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-redis', version:'1.5.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version:'1.5.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version:'1.5.4.RELEASE'
compile group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version:'1.3.0'
compile group: 'mysql', name: 'mysql-connector-java', version:'5.1.38'
compile group: 'com.alibaba', name: 'druid', version:'1.0.28'
compile(group: 'org.quartz-scheduler', name: 'quartz', version:'2.3.0') {
exclude(module: 'c3p0')
}
compile group: 'commons-lang', name: 'commons-lang', version:'2.6'
compile group: 'commons-fileupload', name: 'commons-fileupload', version:'1.3.1'
compile group: 'commons-io', name: 'commons-io', version:'2.5'
compile group: 'commons-codec', name: 'commons-codec', version:'1.10'
compile group: 'commons-configuration', name: 'commons-configuration', version:'1.10'
compile group: 'org.apache.shiro', name: 'shiro-core', version:'1.3.2'
compile group: 'org.apache.shiro', name: 'shiro-spring', version:'1.3.2'
compile group: 'com.github.axet', name: 'kaptcha', version:'0.0.9'
compile group: 'com.qiniu', name: 'qiniu-java-sdk', version:'[7.2.0, 7.2.99]'
compile group: 'com.aliyun.oss', name: 'aliyun-sdk-oss', version:'2.5.0'
compile(group: 'com.qcloud', name: 'cos_api', version:'4.4') {
exclude(module: 'slf4j-log4j12')
}
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'1.5.4.RELEASE') {
exclude(module: 'commons-logging')
}
compile('com.h2database:h2')
deployerJars "org.apache.maven.wagon:wagon-ssh:2.2"
}
9、同步gradle下載依賴庫
10、環境好了,新增測試controller
package com.masonliu.cc; /**
* Created by liumeng02 on 2017/10/30.
*/
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class TestController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(TestController.class, args);
}
}
三、啟動
1、命令列啟動
gradlew bootRun
2、執行TestController的Main方法
四、效果
1、在瀏覽器內開啟http://localhost:8080
2、整體專案結構
相關文章
- IDEA建立SpringBoot的多模組專案教程IdeaSpring Boot
- IDEA使用Gradle構建SpringBoot專案工程IdeaGradleSpring Boot
- idea建立springboot專案IdeaSpring Boot
- idea 建立springboot專案IdeaSpring Boot
- 使用Gradle構建多模組SpringBoot專案GradleSpring Boot
- 使用IDEA建立springboot專案IdeaSpring Boot
- IDEA 快速建立 SpringBoot 專案IdeaSpring Boot
- Gradle構建SpringBoot專案GradleSpring Boot
- _005_SpringBoot_使用IDEA建立SpringBoot專案Spring BootIdea
- 1.idea建立springboot專案IdeaSpring Boot
- 使用gradle構建springboot專案GradleSpring Boot
- Gradle學習系列—-多專案構建Gradle
- Gradle學習系列----多專案構建Gradle
- IDEA建立SpringBoot專案(詳細教程)IdeaSpring Boot
- SpringBoot學習——用Gradle搭建第一個專案Spring BootGradle
- Springboot建立maven多模組專案Spring BootMaven
- 利用IDEA建立gradle構建的Java多模組專案(太清晰了)IdeaGradleJava
- 基於IDEA的SpringBoot專案建立(三)——thymeleafIdeaSpring Boot
- 用Idea 2019.3+和Gradle5.2.1+ 構建SpringBoot多專案(二)IdeaGradleSpring Boot
- 【Java】【Gradle】Gradle構建SpringBoot專案,Gradle模組化管理JavaGradleSpring Boot
- _003_SpringBoot_使用IDEA快速建立一個SpringBoot專案Spring BootIdea
- 使用IDEA建立gradle專案IdeaGradle
- Gradle入門及SpringBoot專案構建GradleSpring Boot
- 使用idea新建springBoot+Gradle專案(超詳細)IdeaSpring BootGradle
- springboot gradle demo (使用 Gradle 構建的 Spring Boot專案)Spring BootGradle
- SpringBoot學習日記(二)多模組專案Spring Boot
- 【SpringBoot學習筆記】-IDEA中使用gradle和MybatisSpring Boot筆記IdeaGradleMyBatis
- IDEA社群版(IDEA Community Edition)建立Springboot父子專案IdeaUnitySpring Boot
- 如何構建多模組的SpringBoot專案Spring Boot
- [Gradle中文教程系列]-跟我學Gradle-8.2-多模組專案- 專案結構Gradle
- IDEA+gradle將springBoot專案打可執行的Jar包IdeaGradleSpring BootJAR
- Gradle建立多模組專案Gradle
- idea使用gradle搭建SpringBootIdeaGradleSpring Boot
- IDEA建立SpringMVC+Gradle專案IdeaSpringMVCGradle
- IntelliJ IDEA 建立Gradle/Java 專案IntelliJIdeaGradleJava
- Gradle入門系列(5):建立多專案構建Gradle
- Idea intellij jdk 1.7通過maven建立Springboot專案IdeaIntelliJJDKMavenSpring Boot
- SpringBoot學習之資料結構Spring Boot資料結構