新建gradle项目 并添加springboot框架支持

来源:互联网 发布:新电脑怎么连接网络 编辑:程序博客网 时间:2024/05/21 19:34

开发工具:Intellij IDEA

所需开发环境:JDK Gradle

参考文档:http://projects.spring.io/spring-boot/#quick-start

一、新建项目

1.  New project


二、选择gradle,假如该项目仅仅作为服务端,不提供视图,则只选择Java即可


2. 填写GroupId ArtifactId version

groupId:项目属于哪个组,这个组往往和项目所在的组织或公司存在关联

artifactId:当前gradle项目在组中唯一的ID

version:项目当前的版本


3. 设置Gradle home


4. 设置项目路径


二、搭建springboot 框架

1. 在build.gradle 文件中添加相应的依赖,引入springboot相关jar包

group 'edu.cueb.weeking'version '1.0-SNAPSHOT'apply plugin: 'java'apply plugin: 'war'sourceCompatibility = 1.8repositories {    mavenCentral()}dependencies {    compile("org.springframework.boot:spring-boot-starter-web:1.5.7.RELEASE")    testCompile group: 'junit', name: 'junit', version: '4.11'    testCompile group: 'junit', name: 'junit', version: '4.12'}

2. 新建package


3. 新建Java Class--->Application ,这是springboot的启动入口


package edu.cueb.weeking;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;@EnableAutoConfigurationpublic class Application {    public static void main(String[] args) throws Exception {        SpringApplication.run(Application.class, args);    }}
4. 新建controller,用于接受客户端的请求

package edu.cueb.weeking.contoller;import org.springframework.boot.*;import org.springframework.boot.autoconfigure.*;import org.springframework.stereotype.*;import org.springframework.web.bind.annotation.*;@Controllerpublic class TestController {    @RequestMapping("/")    @ResponseBody    public String test() {        return "Hello World!";    }}


三、启动Springboot

1、edit configurations

2. defaults 里面配置springboot server,然后点击加号,为该项目配置启动服务



四、启动成功



原创粉丝点击