Gradle创建springboot项目
来源:互联网 发布:正在激活windows 错误 编辑:程序博客网 时间:2024/06/05 17:51
使用Gradle创建一个最简单的Spring Boot项目及测试
idea软件Gradle构建项目
在下载好的项目里,用gradle build编译项目,再执行build下的libs的jar文件:java -jar build下的libs的jar。
修改 build.gradle 文件
group 'com.jpq'version '1.0-SNAPSHOT'apply plugin: 'java'apply plugin: 'spring-boot'sourceCompatibility = 1.8targetCompatibility = 1.8buildscript { ext { springBootVersion = '1.5.6.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") }}repositories { mavenCentral() maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }}dependencies { compile('org.springframework.boot:spring-boot-starter-web') testCompile('org.springframework.boot:spring-boot-starter-test')}
在controller层新建hellocontroller类:
@RestControllerpublic class HelloController { @RequestMapping("/hello") public String sdd(){ return "Hello,world"; }}
新建application类
@SpringBootApplicationpublic class Application { public static void main(String[] args){ SpringApplication.run(Application.class,args); }}
新建测试类test:(注意最后三项的导入)
import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.http.MediaType;import org.springframework.test.context.junit4.SpringRunner;import org.springframework.test.web.servlet.MockMvc;import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;import static org.hamcrest.Matchers.equalTo;import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;/** * 校验helloController的/hello */@RunWith(SpringRunner.class)@SpringBootTest@AutoConfigureMockMvcpublic class HelloControllerTest { @Autowired private MockMvc mockmvc; @Test public void contextLoads() throws Exception { mockmvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string(equalTo("Hello,world"))); }}
阅读全文
0 0
- Gradle创建springboot项目
- 使用gradle 创建springboot项目
- idea+springboot+gradle创建项目
- 使用IDEA+GRADLE创建springboot项目
- idea 下gradle创建springboot 项目
- 使用idea+gradle创建springboot项目
- IDEA下gradle创建springboot项目
- IDEA下创建Springboot,thymeleaf,Mybatis,Postgresql,Gradle项目
- IDEA下创建Springboot,freemarker,mockserver,Gradle项目
- [SpringBoot学习]-IDEA创建Gradle多Module结构的SpringBoot项目
- 快速创建一个基于Gradle构建的SpringBoot Web项目(SpringBoot-01)
- 创建一个springboot项目
- SpringBoot创建Web项目
- springboot项目创建问题
- idea创建springboot项目
- springboot项目创建
- SpringBoot学习-项目创建
- 创建一个springboot项目
- 欢迎使用CSDN-markdown编辑器
- dubbo与keeper碰到不能传输的问题
- 爬格子呀4-2
- 禁止浏览器ctrl+鼠标滚动
- Lucky Number ZOJ
- Gradle创建springboot项目
- Binary Tree Preorder Traversal问题及解法
- 语音识别的技术原理是什么?
- light oj-1282 Leading and Trailing
- ubuntu10.04中没有eth0,只有eth1和eth2
- 关于python科学计算库numpy学习总结
- Android EditText获取焦点失去焦点监听
- SpringMVC在web.xml中配置DispatcherServlet拦截了静态资源访问
- Mysql查询表&列名