美文网首页
maven+eclipse创建第一个spring-boot项目

maven+eclipse创建第一个spring-boot项目

作者: 帅哥_刷哥 | 来源:发表于2017-09-04 06:57 被阅读7816次

1.创建Maven项目

image.png

2.选择项目类型

image.png

3.选择项目

image.png

4.编写项目组和名称-finish即可

image.png

5.修改pom.xml文件

<!-- spring boot基本环境 -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
</parent>
image.png

6.pom.xml中添加依赖

<!--web应用基本环境配置 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
image.png

7.pom.xml中添加编译插件

<build>
    <plugins>
        <!-- spring-boot-maven-plugin插件就是打包spring boot应用的 -->
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
image.png

8.基础包和类

image.png

9.App.java

package com.shuai.spring_boot_1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {
    
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}
image.png

10.OneController.java

package com.shuai.spring_boot_1.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OneController {

    @RequestMapping("/")
    @ResponseBody
    public String index(){
        return "hello spring boot";
    }
}
image.png

11.启动项目

运行 App.java 中的 main方法

12.访问项目

http://localhost:8080/
会访问到 OneController.java 中的index方法

相关文章

网友评论

      本文标题:maven+eclipse创建第一个spring-boot项目

      本文链接:https://www.haomeiwen.com/subject/tjszdxtx.html