您的位置:首页 > 编程语言 > Java开发

springboot:无插件创建Springboot项目

2018-10-11 20:39 429 查看

一、环境信息

  1. 工具:Eclipse、Maven、JDK
  2. 版本:
    - JDK:

    - Maven:
  3. Maven配置:

二、创建springboot项目

  1. 检查eclipse是否关联Maven

  2. 创建Maven项目


  3. 引入Springboot依赖关系
    1. 在pom中添加以下内容

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    </parent>
    <!-- Add typical dependencies for a web application -->
    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    </dependencies>
    <!-- Package as an executable jar -->
    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    </plugins>
    </build>
    [ol] 更新该项目
  4. 当项目无报错标识时即完成
[/ol]

三、springboot启动类

四、springboot配置文件
springboot配置文件可分为两种方式:1.application.properties 2.application.yml
建议使用application.yml配置文件
优点:

  1. 编写方便。例如:
    properties写法:

    server.port=8080
    server.servlet.context-path=/spring

    yml写法:

    server:
    port: 8080
    servlet:
    context-path: /spring
  2. 易于配置时分组

五、Hello SpringBoot!
以上配置完成后,就可以开始写springboot项目了!!!
首先我们检验一下:

  1. 创建一个HelloController.java

    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    @RestController
    public class HelloController {
    @RequestMapping(value = "hello", method= RequestMethod.GET)
    public String hello() {
    return "Hello Spring Boot!";
    }
    }
  2. 然后启动该springboot项目

  3. 在网页访问该项目
    由于我们在application.yml中配置了context-path,所以访问时需加入配置的名称,我这里配置的为spring

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: