入门文档:https://github.com/qibaoguang/Spring-Boot-Reference-Guide

安装gradle

官方下载 https://gradle.org/gradle-download/,建议用迅雷。

环境变量配置:http://jingyan.baidu.com/article/4d58d541167bc69dd4e9c009.html

首先说一下使用spring-boot开始项目的一些注意事项(针对新手):

  • 为了方便,请抛弃配置XML,真的很冗杂
  • 全面支持annotation注解和java config
  • spring-boot提供的一系列starter开始你的项目
  • spring-boot只是帮你更好的开始一个项目,而不是一个应用框架
  • 请使用IDEA开发
开始一个web项目

插件配置:

idea的模型 https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModel.html

spring boot插件(配置了该插件后才有 gradle bootRun任务) http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html

新建文件夹bootmkdir boot,在boot根目录执行gradle init --type java-library,修改build.gradle添加依赖compile 'org.springframework.boot:spring-boot-starter-web',新建Application.java

@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}

写一个简单的controller

@Controller
public class PublicController { @RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
}

boot几乎所有配置都在application.properties里,新建src/main/resources/application.properties,修改端口号server.port=8090,命令行启动gradle bootRun查看http://localhost:8090Hello World!
添加其他功能只需要添加对应的starter然后配置即可,比如通常会用到的一些starter

'org.springframework.boot:spring-boot-starter-web' // web项目
'org.springframework.boot:spring-boot-starter-data-jpa' // JPA对应DAO
'org.springframework.boot:spring-boot-starter-security' // 权限管理
'org.springframework.boot:spring-boot-starter-thymeleaf' // view层,替代JSP
'org.springframework.boot:spring-boot-devtools' // 开发工具,热加载

最后说一下目录结构,一般而言是这样:

|-- build.gradle
|-- src
|----|-- main
|---------|-- java
|--------------|-- com.project
|---------------------|-- controller
|---------------------|-- service
|---------------------|-- repository
|---------------------|-- entity
|---------|-- resources
|--------------|-- application.properties
|--------------|-- application-dev.properties
|--------------|-- application-pro.properties

我推荐这样:

|-- build.gradle
|-- src
|----|-- main
|---------|-- java
|--------------|-- com.project
|---------------------|-- user
|--------------------------|-- controller
|--------------------------|-- service
|--------------------------|-- repository
|--------------------------|-- entity
|---------|-- resources
|--------------|-- application.properties
|--------------|-- application-dev.properties
|--------------|-- application-pro.properties

按组件区分,易查看代码,当项目成长到一定程度更加容易拆分。

热加载

代码热替换 方法一

mvn spring-boot:run

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
<!--
<configuration>
<fork>true</fork>
</configuration>--> </plugin>

代码热加载方法二:

main方法启动

-javaagent:D:/software/springloaded-1.2.6.RELEASE.jar -noverify

模板热替换:

spring.thymeleaf.cache=false

必须按Contrl+F9,太傻了

参考:http://www.jianshu.com/p/ec545ce19bdd
大量的例子:https://github.com/netgloo/spring-boot-samples/tree/master/spring-boot-basewebapp
 很多干货:http://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/
 默认配置的:http://www.tuicool.com/articles/veUjQba

spring boot + gradle[草稿]的更多相关文章

  1. 使用intelliJ创建 spring boot + gradle + mybatis站点

    Spring boot作为快速入门是不错的选择,现在似乎没有看到大家写过spring boot + gradle + mybatis在intellij下的入门文章,碰巧.Net同事问到,我想我也可以写 ...

  2. spring boot + gradle + mybatis

    使用intelliJ创建 spring boot + gradle + mybatis站点   Spring boot作为快速入门是不错的选择,现在似乎没有看到大家写过spring boot + gr ...

  3. Spring boot Gradle项目搭建

    Spring boot Gradle项目搭建 使用IDEA创建Gradle工程     操作大致为:File->new->Project->Gradle(在左侧选项栏中)     创 ...

  4. Spring Boot gradle

    最近有写一个电子订单商务网站,使用JAVA8,SPRING,ANGULARJS对项目使用的技术和大家分享. 第一次写博客,哪有不对需要改正的请联系改正. 因为是项目是我给别人做的无法提供源码见谅,我尽 ...

  5. spring boot gradle build:bootRepackage failed

    When running 'gradle clean build' on my spring boot project (version 1.3.6.RELEASE) on windows 10 (a ...

  6. Spring Boot gradle 集成servlet/jsp 教程及示例

    1.build.gradle 配置 注意,加入了war插件,在依赖中加入了jstl.tomcat-embed-jasper,这样才能运行jsp页面. buildscript { ext { sprin ...

  7. Spring boot + Gradle + Eclipse打war包发布总结

    首先感谢两位博主的分享 http://lib.csdn.net/article/git/55444?knId=767 https://my.oschina.net/alexnine/blog/5406 ...

  8. Spring Boot Gradle 打包可执行Jar文件!

    使用Gradle构建项目,继承了Ant的灵活和Maven的生命周期管理,不再使用XML作为配置文件格式,采用了DSL格式,使得脚本更加简洁. 构建环境: jdk1.6以上,此处使用1.8 Gradle ...

  9. [z]spring boot gradle build

    I had the same problem. I believe it is caused by the JRE that gradle is configured to use rather th ...

随机推荐

  1. Hotaru's problem(hdu 5371)

    题意:给出一个数字串,询问最长的子串,满足以下要求:将子串平均分为三部分,一三部分相等,一二部分对衬. /* 在manachar的基础上,枚举回文串的中心,再找第三部分. */ #include< ...

  2. LeetCode之136. Single Number

    -------------------------------------- 一个数异或它自己会得到0,0异或n会得到n,所以可以用异或来消除重复项. AC代码如下: public class Sol ...

  3. ubuntu 16.04 设置位wifi热点 方法(手机可链接)亲测可用

    Ubuntu16.04里面可以直接创建热点,而不用像以前的版本,还要其他辅助工具. 具体步骤如下: 1. 点击有上角网络标志,点开编辑链接. 2. 选择 WiFi ,添加一个网络. 3.设置这个网络 ...

  4. [转]js 将图片连接转换称base64格式

    参考:http://blog.csdn.net/wyyfwm/article/details/45917255 我们把图像文件的内容直接写在了HTML 文件中,这样做的好处是,节省了一个HTTP 请求 ...

  5. 【chrome插件】web版微信接入图灵机器人API实现自动回复

    小贱鸡自动回复API已经不可以用了,现在改良接入图灵机器人API 360chrome浏览器团队翻译了部分谷歌插件开发文档 地址:http://open.chrome.360.cn/extension_ ...

  6. Oracle的索引适用范围

    若字段数据的重复率不是很高,而且数据量不是很大,考虑B树索引: 若字段数据的重复率较高,而且查询中有特定的查询方式(比如列之间有或,与等逻辑运算),则考虑位图索引: 若对列中的字段进行模糊查询或者语言 ...

  7. SpringMvc的创建流程以及2种加载配置文件的方式

    1.首先创建个web项目,第一步导入相应的jar包,并且buildtoPath 2.用elipse或myeclipse点击进入web.xml中 按住 Alt+ / 有个提示 找到前面带 #Dispat ...

  8. 数位DP GYM 100827 E Hill Number

    题目链接 题意:判断小于n的数字中,数位从高到低成上升再下降的趋势的数字的个数 分析:简单的数位DP,保存前一位的数字,注意临界点的处理,都是套路. #include <bits/stdc++. ...

  9. Two Sum

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  10. 【5集iCore3_ADP演示视频】5-4 iCore3与应用开发平台的组装与拆卸

    iCore3双核心应用开发平台基于iCore3双核心板,包含ARM.FPGA.7寸液晶屏.双通道数字示波器.任意波发生器.电压表等模块,是一款专为电子爱好者设计的综合性电子学习系统. [视频简介]本视 ...