Gradle构建SpringBoot(Eclipse)

Gradle构建SpringBoot

1.配置build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.0/userguide/java_library_plugin.html
 */
plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
    id 'org.springframework.boot' version '2.1.1.RELEASE'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    //jcenter()
    // 优先使用国内源
    maven { url 'https://maven.aliyun.com/repository/public' }
    mavenCentral()
}

// 指定java版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
// 使用spring boot
apply plugin: "org.springframework.boot"
// 使用spring boot的自动依赖管理
apply plugin: 'io.spring.dependency-management'  //应用的插件

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

	// 让spring-boot支持gradle
    //classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.1.RELEASE")
    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:28.0-jre'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-devtools'
	
    // Use JUnit test framework
    //testImplementation 'junit:junit:4.12'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    
}

2.配置SpringBootApplication项目启动类

package com.lius;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {

	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

3.配置Controller

package com.lius.controllers;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>测试Controller类</p>
 * @author lius
 *
 */
@RestController  //@Controller+@ResponseBody
public class testController {

	//测试接口
	@RequestMapping("/test")
	public String gradleController() {
		
		return String.format("<h1><center style=\"color:red;font-style:italic;\">%s</center></h1>",
				"Welcome to use SpringBoot of Gradle!");
	}
}

4.构建成功

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值