入门文档: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. React学习笔记-1-什么是react,react环境搭建以及第一个react实例

    什么是react?react的官方网站:https://facebook.github.io/react/下图这个就是就是react的标志,非常巧合的是他和我们的github的编辑器Atom非常相似. ...

  2. Sublime Text 2报“Decode error - output not utf-8”错误的解决办法

    [Decode error - output not utf-8] [Decode error - output not utf-8]   应该怎么办?   这是因为python配置的编译环境的编码不 ...

  3. 【C#】 知乎用户网络爬虫

    目的 由一个种子用户出发,抓取相关的关注者和被关注者,然后再延伸开抓取更多的相关用户,以便后期进行数据分析. 拓扑图 开发工具 编程语言:C# 数据库:SqlServer 2008 R2 程序架构 流 ...

  4. 为何Redis要比Memcached好用(转)

    转载链接:http://blog.csdn.net/renfufei/article/details/40598889 GitHub版本地址: https://github.com/cncounter ...

  5. 大部分人都会做错的经典JS闭包面试题

    由工作中演变而来的面试题 这是一个我工作当中的遇到的一个问题,似乎很有趣,就当做了一道题去面试,发现几乎没人能全部答对并说出原因,遂拿出来聊一聊吧. 先看题目代码: function fun(n,o) ...

  6. C++ 定义全局数组

    数组怎么用,全局数组就怎么用,只是他的作用域不一样才叫全局数组... 在A.h 或 A.cpp中定义char buf[10]; 如果在B.cpp要用,就在其开头中写成 extern char buf[ ...

  7. 移动端使用让图片或者div垂直居中

    ._limgMIiddle{ /* Firefox */ display:-moz-box; -moz-box-pack:center; -moz-box-align:center; /* Safar ...

  8. Bulk_Collect_Performance 比较

    上一篇讲到了调用集锦,这篇关注一下性能问题吧. DECLARE CURSOR c_tool_list IS SELECT descr d1 FROM hardware; l_descr hardwar ...

  9. Hello cnblog!

    Test Markdown #!/usr/env/python # coding: utf-8 # 这是一个测试文件 print "hahah" def t(): print &q ...

  10. 【BZOJ】3526: [Poi2014]Card

    题意 \(n(n \le 200000)\)张卡片,正反有两个数\(a[i], b[i]\).\(m(m \le 1000000)\)次操作,每次交换\(c[i].d[i]\)位置上的卡片.每一次操作 ...