8使用Gradle构建Spring_Boot应用

(1)创建项目
->Create New Project
->Gradle 和Java(Additional Libraries and Frameworks) ->next
->GroupId   :com.shengsiyuan
  ArtifactId:spring_lecture
  Version   :1.0
->Name: spring_lecture
->Location: E:\\spring_lecture
-> Use auto-import

(2)修改文件
build.gradle
-------------------------------------------------------------
buildscript {
    ext{
        springBootVersion='2.2.5.RELEASE'
    }
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
        mavenCentral()
    }
    dependencies {
        classpath(
                "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}",
                "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE"
        )
    }
}

apply {
    plugin("java")
    plugin("maven")
    plugin("idea")
    plugin("org.springframework.boot")
    plugin("io.spring.dependency-management")
}
group 'com.shengsiyuan'
version '1.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
    maven { url 'https://plugins.gradle.org/m2/' }
    maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
    maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    mavenCentral()
}

dependencies {
    compile(
            "org.springframework.boot:spring-boot-starter-web"
    )
}


------------------------------------------------------------------------

其中说明
dependencies {
        classpath(
                "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}",//提供boot run bootbuild等命令
                "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE" //加载相关依赖
        )
    }

建立相关的Jar包,启动类先建立起来
main->java目录右键->Mark Directory as    ->Sources Root
main->resources   ->Mark Directory as    ->resources root
test->java        ->Mark Directory as    ->test resources root
test->resources   ->Mark Directory as    ->test resources root

src->main->java->新建一个包 com.shengsiyuan.boot
src->main->java->新建一个包 com.shengsiyuan.boot->新建类->MyApplication
src->main->java->新建一个包 com.shengsiyuan.boot.controller ->新建类->MyController
src->main->java->新建一个包 com.shengsiyuan.boot.domain ->新建类->Person
src->main->java->resources->新建文件application.yml


运行程序
(1)main->java->com.shengsiyuan.boot->MyApplication主类中->右键-> Run MyApplication
(2)右上角->Gradle->spring_lecture->Tasks->application->bootRun
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值