spring boot + gradle[草稿]
入门文档: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:8090,Hello 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,太傻了
spring boot + gradle[草稿]的更多相关文章
- 使用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 ...
- Spring boot Gradle项目搭建
Spring boot Gradle项目搭建 使用IDEA创建Gradle工程 操作大致为:File->new->Project->Gradle(在左侧选项栏中) 创 ...
- Spring Boot gradle
最近有写一个电子订单商务网站,使用JAVA8,SPRING,ANGULARJS对项目使用的技术和大家分享. 第一次写博客,哪有不对需要改正的请联系改正. 因为是项目是我给别人做的无法提供源码见谅,我尽 ...
- 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 ...
- Spring Boot gradle 集成servlet/jsp 教程及示例
1.build.gradle 配置 注意,加入了war插件,在依赖中加入了jstl.tomcat-embed-jasper,这样才能运行jsp页面. buildscript { ext { sprin ...
- Spring boot + Gradle + Eclipse打war包发布总结
首先感谢两位博主的分享 http://lib.csdn.net/article/git/55444?knId=767 https://my.oschina.net/alexnine/blog/5406 ...
- Spring Boot Gradle 打包可执行Jar文件!
使用Gradle构建项目,继承了Ant的灵活和Maven的生命周期管理,不再使用XML作为配置文件格式,采用了DSL格式,使得脚本更加简洁. 构建环境: jdk1.6以上,此处使用1.8 Gradle ...
- [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 ...
随机推荐
- LRU算法
LRU,Least recently used[最近最少使用算法],该算法[或变种]被广泛用于缓存管理中,其设计思想是基于:经常被访问的数据在未来一段时间也会被访问,最近最少被访问的数据在未来一段时间 ...
- margin-before: 1em; margin-after: 1em;margin-start:0px;margin-end: 0px;
总的来说:这是CSS3.0的对于文章段P容器的定义方法语句!display:block这个样式,只定义了P容器为一个块;后面四句是CSS3中的样式定义方法:-webkit-margin-before: ...
- Linux常用命令学习7---(磁盘管理df du、磁盘的分区和格式化fdisk parted)
1.磁盘管理 在服务器的维护中,我们需要关心服务器的磁盘使用了多少.还有多少的剩余空间.某个文件有多大.某个文件夹内的所有文件在一起一共占用的多少空间……问题.以便我们在合适的时机为服务器添加硬 ...
- node+fis3搭建
node安装: 到https://nodejs.org/en/download/releases下载编译好的包, 如:https://nodejs.org/download/release/v4.4. ...
- 注解:【有连接表的】Hibernate双向1->N关联 (N端、1端同时参与控制关联关系)
Person与Address关联:双向1->N,[有连接表的],N端.1端同时参与控制关联关系 Person.java package org.crazyit.app.domain; impor ...
- Linux第03天
Linux 第03天 1.Linux帐号和ACL权限管理 1.帐号和用户组 1.1 用户标识符————UID(root为0 系统用户为1~499 普通用户为500~65535) 1.2 用户组标识符— ...
- HDU 2069 Coin Change(完全背包变种)
题意:给你5种银币,50 25 10 5 1,问你可以拼成x的所有可能情况个数,注意总个数不超过100个 组合数问题,一看就是完全背包问题,关键就是总数不超过100个.所有我们开二维dp[k][j], ...
- 【随笔】MQTT简介
我们知道,将用户使用的设备称为客户端,将提供给用户信息的端口称为服务器端.两个端口之间可以通过多种通信协议进行交互,比如HTTP(同步)或者基于消息传递的异步. HTTP是一种同步无状态的协议,不支持 ...
- poj2631 求树的直径裸题
题目链接:http://poj.org/problem?id=2631 题意:给出一棵树的两边结点以及权重,就这条路上的最长路. 思路:求实求树的直径. 这里给出树的直径的证明: 主要是利用了反证法: ...
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...