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.構建成功
Gradle構建SpringBoot(Eclipse)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.