Springboot项目搭建

一、简介

Springboot是Spring社区发布的一个开源项目,用于快速构建Spring项目,习惯因为配置的方式,极大简化开发过程,减小传统的开发中繁琐的配置,内置Servlet容器、Tomcat、jetty,更多的好处只有上手了才知道java

二、构建

一、构建项目git

  • IntelliJ IDEA 能够自行下载web

  • 选择构建Maven项目spring

  • 选择JDKspringboot

  • 能够直接点Next,不用去选择构建类型app

maven

  • GroupId:公司域名倒序spring-boot

  • ArtifactId:项目名称测试

  • Version:版本号,默认不用变code

二、引入springboot相关依赖

  • springboot父依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>

  • 添加web支持 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>

三、启动类

  • @SpringBootApplication是springboot的核心注解

    package com.test.controller; 
      import org.springframework.boot.SpringApplication; 
      import org.springframework.boot.autoconfigure.SpringBootApplication; 
      @SpringBootApplication 	public class StartApplication { 
      	public static void main(String[] args) { 
      		SpringApplication.run(StartApplication.class, args); 
      	} 
      }
  • 写一个controller

    package com.test.controller; 
      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 "My SpringBoot"; 
      	} 
      }

三、启动Springboot

启动方法有不少种

  1. 直接运行启动类的main方法

  2. maven项目中

  1. java -jar springboot1-1-0.0.1-SNAPSHOT.jar

  2. 其余方式,能够自行发掘

四、yml配置

springboot项目的基本配置文件放在resource目录下,两种方式,推荐yml

  1. application.yml

  2. application.properties

五、测试

码云:https://gitee.com/guanxf/springboot1-1

相关文章
相关标签/搜索