搭建Springboot工程
可以选择自己手动搭建,也可以选择start.spring.io快速搭建。
偷懒直接用,生成工程。
- 选择构建工具:Maven或者Gradle。我选了Gradle,这也是我第一次用gradle。
- 选择SpringBoot版本
- Dependencies中搜索自己想依赖的包,比如ElasticSearch
- 生成是单module项目。
- 下载后导入工程,可以开始干活了。
- 下图为新增module后的截图
- 新增module后会自动新增一个setting.gradle文件,没有则手动新建一个。
- 修改gradle版本: gradle-wrapper.properties(gradle安装和maven一样)
- 修改repositories 地址 ** init.gradle**,默认为maven.oschina.net(貌似不能用了)改为maven.aliyun.com;
- 修改gradle内容:依赖以及设置 build.gradle
- build项目;
- 完成项目搭建
gradle-wrapper.properties
#Tue Jan 10 11:28:22 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
init.gradle: C:\Users\xxxxx.gradle
allprojects{
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
remove repo
}
}
}
maven {
url REPOSITORY_URL
}
}
}
setting.gradle内容
rootProject.name = 'bootcwenao'
include 'common-bootcwenao'
include 'apigateway-bootcwenao'
include 'discovery-bootcwenao'
include 'configserver-bootcwenao'
项目 build.gradle
buildscript {
ext {
springBootVersion = '1.4.3.RELEASE'
}
repositories {
mavenCentral()
maven { url "http://maven.aliyun.com/nexus/content/repositories/snapshots"}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
allprojects {
apply plugin: 'idea'
group = 'com.bootcwenao'
version = '1.0-SNAPSHOT'
}
subprojects {
ext {
springCloudVersion = 'Camden.SR3' //'Brixton.RELEASE'
mybatisSpringBootVersion='1.2.0'
mybatisVersion = '3.2.8'
mysqlVersion = '5.1.38'
okhttpVersion = '3.4.1'
druidVersion = '1.0.18'
commonsLang3Version = '3.4'
snappyVersion = '1.1.2.1'
}
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
maven { url "http://maven.aliyun.com/nexus/content/repositories/snapshots"}
mavenCentral()
}
sourceSets {
main {
java.srcDir('src/main/java')
resources.srcDir('src/main/resources')
}
test {
java.srcDir('src/test/java')
resources.srcDir('src/test/resources')
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.3'
}
}
代码
代码请移步 Github参考地址
如有疑问请加公众号(K171),如果觉得对您有帮助请 github start