Spring boot Gradle项目搭建
Spring boot Gradle项目搭建
使用IDEA创建Gradle工程
操作大致为:File->new->Project->Gradle(在左侧选项栏中)
创建常规以后生成的工程目录如下:
- build
- gradle
- wrapper
- gradle-wrapper.jar
- gradle-wrapper.properties
- wrapper
- src
- java
- resources
- test
- java
- resources
- build.gradle
- gradlew
- gradlew.bat
- settings.gradle
配置Spring boot
下面需要对两个文件进行编辑:
build.gradle文件修改后的内容如下,依赖一般是前面是groupId,中间是artifactId,第三个一般是版本。在repositories配置使用阿里云的仓库,避免下载过慢。
plugins {
id 'java'
id 'com.gradle.build-scan' version '2.0.2'
id 'org.springframework.boot' version '2.0.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.7.RELEASE'
}
group 'seckill'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'org.springframework.boot:spring-boot-dependencies:2.0.5.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
components {
withModule('org.springframework:spring-beans') {
allVariants {
withDependencyConstraints {
// Need to patch constraints because snakeyaml is an optional dependency
it.findAll { it.name == 'snakeyaml' }.each { it.version { strictly '1.19' } }
}
}
}
}
}
buildScan {
// always accept the terms of service
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
// always publish a build scan
publishAlways()
}
setting.gradle文件修改后的内容如下:
rootProject.name = 'seckill'
enableFeaturePreview('IMPROVED_POM_SUPPORT')
编写类
首先在src/java下生成源码目录com.seckill.spring(相当于com/seckill/spring)
在src/java下创建程序入口类Application.java,其内容如下:
package com.seckill.spring;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
在src/java/com.seckill.spring下创建目录controllers,并在controllers目录创建类:HelloWorld,在其中定义根路由并返回Hello World,其代码如下:
package com.seckill.spring.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
public class HelloWorld {
@RequestMapping(value = "/", method = RequestMethod.GET)
public Map helloWorld() {
Map<String, Object> ret = new HashMap<>();
ret.put("ret", "Hello World");
return ret;
}
}
运行访问
- 运行Application类,可以在控制台看到起默认监听在8080端口
- 浏览器访问:localhost:8080,可以看到返回字符串Hello World
参考链接
- 1.Building Spring Boot 2 Applications with Gradle
- 2.Learn Spring Boot
- 3.Building a RESTful Web Service
- Gradle配置阿里云Maven镜像仓库地址
Spring boot Gradle项目搭建的更多相关文章
- SpringCloud 微服务一:spring boot 基础项目搭建
spring cloud是建立在spring boot的基础上的,而之前虽然听说过,也随便看了一下spring boot,却没有真正使用,因此还必须先花时间学一下spring boot. spring ...
- 【Spring boot】【gradle】idea新建spring boot+gradle项目
在此之前,安装了idea/jdk/gradle在本地 ===================================== gradle怎么安装:http://www.cnblogs.com/s ...
- Spring Boot gradle
最近有写一个电子订单商务网站,使用JAVA8,SPRING,ANGULARJS对项目使用的技术和大家分享. 第一次写博客,哪有不对需要改正的请联系改正. 因为是项目是我给别人做的无法提供源码见谅,我尽 ...
- 使用intelliJ创建 spring boot + gradle + mybatis站点
Spring boot作为快速入门是不错的选择,现在似乎没有看到大家写过spring boot + gradle + mybatis在intellij下的入门文章,碰巧.Net同事问到,我想我也可以写 ...
- spring boot + gradle + mybatis
使用intelliJ创建 spring boot + gradle + mybatis站点 Spring boot作为快速入门是不错的选择,现在似乎没有看到大家写过spring boot + gr ...
- 15 个优秀开源的 Spring Boot 学习项目,一网打尽!
Spring Boot 算是目前 Java 领域最火的技术栈了,松哥年初出版的 <Spring Boot + Vue 全栈开发实战>迄今为止已经加印了 8 次,Spring Boot 的受 ...
- 【spring】1.2、Spring Boot创建项目
Spring Boot创建项目 在1.1中,我们通过"Spring Starter Project"来创建了一个项目,实际上是使用了Pivotal团队提供的全新框架Spring B ...
- 15 个优秀开源的 Spring Boot 学习项目
Spring Boot 算是目前 Java 领域最火的技术栈了,松哥年初出版的 <Spring Boot + Vue 全栈开发实战>迄今为止已经加印了 8 次,Spring Boot 的受 ...
- spring boot 开发环境搭建(Eclipse)
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
随机推荐
- MySQL 5.6, 5.7, 8.0版本的新特性汇总大全
转载:http://blog.itpub.net/15498/viewspace-2650661/ MySQL 5.6 1).支持GTID复制 2).支持无损复制 3).支持延迟复制 4).支持基于库 ...
- 登录网站的autohotkey脚本
;如果需要这个软件的代码逻辑,删除敏感信息只需要把上面3行代码删除即可. !:: ;login经过测试必须用ie浏览器,在默认软件里面浏览器设置成ie即可,其他浏览器不让send密码 ;虽然通过程序把 ...
- kickstart批量装机脚本
#!/bin/bash #安装必备的软件 yum -y install dhcp tftp-server tftp xinetd syslinux vsftpd yum -y install *kic ...
- [Javascript] How to deal with floating number
What's your expect of the output?: console.log(0.1 + 0.2 === 0.3); The answer is 'false'. Because: 0 ...
- axios请求提交的form data格式 明明是JSON格式的参数却转成了字符串格式
问题:传的参数成为了字符数格式 解决:把参数的格式转换 const params = new URLSearchParams() params.append('USER_LOGIN', 'admin' ...
- 原生JS实现拖动滑块验证登录效果
♀分享一组利用原生JS实现拖动滑块验证效果 ♀在这个组代码中涉及三个方面的知识: ⑴事件处理 ⑵添加验证标记 ⑶选择器的封装 代码如下: <!DOCTYPE html> <htm ...
- http协议。会话控制cookie、session
http协议是无状态的协议.每次访问页面的http协议都是独立的,正是因为http协议是无状态的,所以导致访问一个页面后再去访问另一个页面的时候,一些数据会消失,比如:用户的登录信息就会消失.那么怎么 ...
- 001_C/C++笔试题_考察C/C++语言基础概念
(一)文章来自:C/C++笔试题-主要考察C/C++语言基础概念.算法及编程,附参考答案 (二)基础概念 2. 头文件中的ifndef/define/endif的作用? 答:防止该头文件被重复引用. ...
- BOOTING ELOQUENT MODEL TRAITS
BOOTING ELOQUENT MODEL TRAITS So I've learnt a little Laravel/Eloquent trick today that is very much ...
- UVAlive 7414 Squeeze the Cylinders a,b,c三种步数 搜索+最短路
题意:给你n个点(n<=50),然后有些点之间会有一条路,路是单向的,每个回合让你走a,b,c三种步数中的任意一种(a,b,c<=100),问你最少需要多少个回合才能保证一定能从1点到达n ...