搭建springboot项目

springboot是什么?

Takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.

百度之后

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。

springboot的好处?

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.

说白了springboot的好处就是减少了spring一直被人诟病的配置文件,springboot是非常适合微服务的。
说了这么多我觉得都是废话还是看如何搭建一个springboot的项目吧!

如何快速搭建一个springboot项目

  • 使用idea构建一个maven项目
    这个搭过web项目的人都应该知道目录结构
  • 引入相应的依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.springboot</groupId>
    <artifactId>springboot-demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
        <java.version>1.7</java.version>
    </properties>
    <!-- springboot-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>
    <dependencies>
        <!-- 引入web模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 测试模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
  • 添加一个启动类
    需要注意的是启动类应该在包的根目录下一定要注意不然很多时候启动是会报错的。
    先看一下启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
 * Created by yuxi on 17/2/16.
 */
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

需要注意的是添加一个springboot的注解:
@SpringBootApplication

  • 添加一个配置文件(这一个就OK了)
    添加一个application.properties
server.context-path=/
server.port=8080

接下来直接run或者debug这个类就OK了!
可以看到对应的springboot彩蛋和日志信息

Connected to the target VM, address: '127.0.0.1:61375', transport: 'socket'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.5.RELEASE)

2017-02-16 15:31:52.149  INFO 5226 --- [           main] com.yuxi.Application                     : Starting Application on yuxideMacBook-Pro.local with PID 5226 (/Users/yuxi/work/myoschina/springboot-demo/target/classes started by yuxi in /Users/yuxi/work/myoschina/springboot-demo)

参考文章:
http://blog.didispace.com/spring-boot-learning-1/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,841评论 18 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,926评论 6 342
  • 先来一段扯皮,本人是个今年刚毕业的小菜鸟(在校主要学的Android)。之前在github发表个几个Android...
    BlackWingXu阅读 1,427评论 0 2
  • Spring Boot的简单介绍 Spring Boot 本身并不提供Spring框架的核心特性以及扩展功能,只是...
    ChinaXieShuai阅读 1,014评论 2 1
  • 单位搬到开发区,来回上下班成了问题,因为不想搭别人的车。 但现在找到了解决的方法:徒步上班、下班! 坚持了两个月...
    凝muo阅读 450评论 0 0