springboot程序员Spring-Boot

搭建springboot项目

2017-02-16  本文已影响242人  小鱼嘻嘻

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项目

<?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

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/

上一篇 下一篇

猜你喜欢

热点阅读