代码改变世界

Java Idea 新建SpringBoot项目

2018-06-06 10:12  那么像你  阅读(57)  评论(0)    收藏  举报

1.下载、安装、配置JDK

2.下载、安装、配置 Maven

  修改下载源

  在Maven的settings.xml 文件的mirrors标签里增加

  

  <mirrors>
     <mirror> 
        <id>alimaven</id> 
        <name>aliyun maven</name> 
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 
        <mirrorOf>central</mirrorOf> 
      </mirror> 
  </mirrors>

 

3.新建项目

 

 

 

 

4.修改Maven配置

 

settings文件要和刚才修改下载源的一致

5.在pom.xml里添加

<!-- spring boot-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>
    <dependencies>
 
        <!-- 引入Web模块 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.3.4.RELEASE</version>
        </dependency>
 
 
    </dependencies>

6.新建Application.java 文件

  先建package com.controller(名字没有特定要求,最好安装这个),在 com.controller下新建Application.java

package com.Controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
 
        SpringApplication.run(Application.class, args);
    }
}

7.新建Controller

package com.Controller;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class Home {
    @RequestMapping("/")
    public String index()
    {
        return  "Hello";
    }

}

8.在Application.java 右键

 

启动 localhost:8080