• 使用maven构建project项目, 配置aliyun仓库, 不赘述
  • springboot 版本需要: jdk1.7+, maven3.2+ , gradle2.9+
  • 配置文件
  1. 引入父包, 放在<project>标签内, 期内包含大量配置好的依赖, 在自己项目中添加这些一来是不需要写<version>

      <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <!--!这里版本不能使用properties配置-->
    <version>1.5..RELEASE</version>
    </parent>

    有时候我们自己公司内有父pom, 不能直接添加parent, 可以通过以下方式

    <dependencyManagement>
    <dependencies>
    <dependency>
    <!-- Import dependency management from Spring Boot -->
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>1.5.2.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>
    </dependencies>
    </dependencyManagement>
  2. 引入web启动包, 因为我们开发的是web工程,所以需要在pom.xml中引入spring-boot-starter-web,spring官方解释说spring-boot-start-web包含了spring webmvc和tomcat等web开发的特性。
    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    </dependencies>
  3. 加入仓库配置, 如果是release版本不需要
    (you don't need this if you are using a .RELEASE version)
    <repositories>
    <repository>
    <id>spring-snapshots</id>
    <url>http://repo.spring.io/snapshot</url>
    <snapshots><enabled>true</enabled></snapshots>
    </repository>
    <repository>
    <id>spring-milestones</id>
    <url>http://repo.spring.io/milestone</url>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>spring-snapshots</id>
    <url>http://repo.spring.io/snapshot</url>
    </pluginRepository>
    <pluginRepository>
    <id>spring-milestones</id>
    <url>http://repo.spring.io/milestone</url>
    </pluginRepository>
    </pluginRepositories>
  4. 直接使用Main启动spring, plugin需要添加, 如果使用 spring-boot:run 不需要此配置
    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin </artifactId>
    </plugin>
    </plugins>
    </build>
  5. 程序主入口
  6. @RestController  //springmvc 注解, 返回给调用者字符串
    @SpringBootApplication // 自动给程序添加默认属性
    public class App { @RequestMapping("/")
    public String hello(){
    return "Hello world!";
    } public static void main(String[] args) {
    SpringApplication.run(App.class, args);
    }
    }
  7. 启动: 运行main函数
    1.   run as : spring-boot:run
    2.   右键, run as java Application

配置pom.xml文件, 使用maven-compiler-plugins插件锁定jdk版本和maven-surefire-plugins插件配置maven-test

<?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.wenbronk</groupId>
<artifactId>SpringBootTest</artifactId>
<version>0.0.1-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent> <!-- Additional lines to be added here... -->
<dependencies>
<!-- web 启动的jar包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!--jpa的jar包 ,操作数据库的,类似hibernate-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> <!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> <!--thymeleaf模板jar,是很不错的html数据传递取值,类似jsp的jstl-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies> <!--maven的插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins> <!-- 配置java版本 不配置的话默认父类配置的是1.6-->
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build> </project>

然后运行maven dependecy:tree, 下载依赖到本地仓库中

注意:

  • java.version属性

    •   spring 默认 使用jdk1.6, 如果想使用1.8, 需要如下配置

      <properties>
      <java.version>1.8</java.version>
      </properties>
    • 添加spring-boot-starter-web依赖

       spring通过spring-boot-starter-*来支持具体的某个功能

        具体请参照: http://docs.spring.io/spring-boot/docs/1.2.3.RELEASE/reference/html/using-boot-build-systems.html#using-boot-starter-poms

错误: 

  1. 使用1.5.1版本一直报错

    [INFO] Scanning for projects...
    [ERROR] [ERROR] Some problems were encountered while processing the POMs:
    [FATAL] Non-parseable POM C:\Users\231\.m2\repository\org\springframework\boot\spring-boot-dependencies\1.5.1.RELEASE\spring-boot-dependencies-1.5.1.RELEASE.pom: only whitespace content allowed before start tag and not o (position: START_DOCUMENT seen o... @1:1) @ C:\Users\231\.m2\repository\org\springframework\boot\spring-boot-dependencies\1.5.1.RELEASE\spring-boot-dependencies-1.5.1.RELEASE.pom, line 1, column 1
    @
    [ERROR] The build could not read 1 project -> [Help 1]
    [ERROR]
    [ERROR] The project com.example:myproject:0.0.1-SNAPSHOT (E:\iwhere\SpringBootTest\pom.xml) has 1 error
    [ERROR] Non-parseable POM C:\Users\231\.m2\repository\org\springframework\boot\spring-boot-dependencies\1.5.1.RELEASE\spring-boot-dependencies-1.5.1.RELEASE.pom: only whitespace content allowed before start tag and not o (position: START_DOCUMENT seen o... @1:1) @ C:\Users\231\.m2\repository\org\springframework\boot\spring-boot-dependencies\1.5.1.RELEASE\spring-boot-dependencies-1.5.1.RELEASE.pom, line 1, column 1 -> [Help 2]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
    [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/ModelParseException

    解决: 更换版本为1.5.2就好了.....

springboot 入门的更多相关文章

  1. SpringBoot入门教程(二)CentOS部署SpringBoot项目从0到1

    在之前的博文<详解intellij idea搭建SpringBoot>介绍了idea搭建SpringBoot的详细过程, 并在<CentOS安装Tomcat>中介绍了Tomca ...

  2. SpringBoot入门基础

    目录 SpringBoot入门 (一) HelloWorld. 2 一 什么是springboot 1 二 入门实例... 1 SpringBoot入门 (二) 属性文件读取... 16 一 自定义属 ...

  3. SpringBoot入门示例

    SpringBoot入门Demo SpringBoot可以说是Spring的简化版.配置简单.使用方便.主要有以下几种特点: 创建独立的Spring应用程序 嵌入的Tomcat,无需部署WAR文件 简 ...

  4. Spring全家桶系列–[SpringBoot入门到跑路]

    //本文作者:cuifuan Spring全家桶————[SpringBoot入门到跑路] 对于之前的Spring框架的使用,各种配置文件XML.properties一旦出错之后错误难寻,这也是为什么 ...

  5. springboot入门之一:环境搭建(续)

    在上篇博客中从springboot的入门到运行一个springboot项目进行了简单讲述,详情请查看“springboot入门之一”.下面继续对springboot做讲述. 开发springboot测 ...

  6. 【Java】SpringBoot入门学习及基本使用

    SpringBoot入门及基本使用 SpringBoot的介绍我就不多说了,核心的就是"约定大于配置",接下来直接上干货吧! 本文的实例: github-LPCloud,欢迎sta ...

  7. SpringBoot入门(三)——入口类解析

    本文来自网易云社区 上一篇介绍了起步依赖,这篇我们先来看下SpringBoot项目是如何启动的. 入口类 再次观察工程的Maven配置文件,可以看到工程的默认打包方式是jar格式的. <pack ...

  8. SpringBoot入门(五)——自定义配置

    本文来自网易云社区 大部分比萨店也提供某种形式的自动配置.你可以点荤比萨.素比萨.香辣意大利比萨,或者是自动配置比萨中的极品--至尊比萨.在下单时,你并没有指定具体的辅料,你所点的比萨种类决定了所用的 ...

  9. SpringBoot入门(四)——自动配置

    本文来自网易云社区 SpringBoot之所以能够快速构建项目,得益于它的2个新特性,一个是起步依赖前面已经介绍过,另外一个则是自动配置.起步依赖用于降低项目依赖的复杂度,自动配置负责减少人工配置的工 ...

  10. SpringBoot入门(二)——起步依赖

    本文来自网易云社区 在前一篇我们通过简单几步操作就生成了一个可以直接运行的Web程序,这是因为SpringBoot代替我们做了许多工作,概括来讲可以分为起步依赖和自动配置.这一篇先来看看起步依赖. 项 ...

随机推荐

  1. codeforces 477D

    题意:给定一个长度<=5000的二进制字符串S,以及一个初始为0的n,有一下两种操作: 1. 输出n(n>=1并且为2进制形式输出) 2.n=n+1 每次选择一种操作.. 求:1.有多少方 ...

  2. HyperServer 中的 SSL 支持

    HyperServer 中的 SSL 支持 DLL 模式不需要 SSL 配置, 因为 web 服务器 (如 IIS) 将承担 ssl 配置和 ssl 证书的责任. 对于独立和服务模式, ssl 配置是 ...

  3. [leet code 135]candy

    1 题目 There are N children standing in a line. Each child is assigned a rating value. You are giving ...

  4. 读取ViewBag匿名类

    关于遍历 viewBag匿名类错误 EF tt生成的类 明明有值眼睁睁看着 却不认识 public ActionResult Index() { MyTestEntities1 db = new My ...

  5. Method not found: 'System.Data.Entity.ModelConfiguration.Configuration.XXX

    使用EF flument API  修改映射数据库字段的自增长 modelBuilder.Entity<Invoice>().Property(p => p.Id).HasDatab ...

  6. 【文文殿下】[CEOI2004]锯木厂选址 题解

    题解 我们枚举建厂的位置,发现有个\(n^2\)的DP.随手搞个斜率优化到\(O(n)\). #include<bits/stdc++.h> using namespace std; ty ...

  7. [LNOI2014]LCA(树剖+线段树)

    \(\%\%\% Fading\) 此题是他第一道黑题(我的第一道黑题是蒲公英) 一直不敢开,后来发现是差分一下,将询问离线,树剖+线段树维护即可 \(Code\ Below:\) #include ...

  8. jdk在Linux下的安装

    之前学linux的时候,也是赶鸭子上架,照着教程一步一步的走,但是今天linux出现了点问题重装一下 重新学习一些linux下常需软件的安装 一般我们再装完系统后,装的匆忙,先把ip搞出来 切换到该目 ...

  9. Django(框架、模板)

    day65 参考:https://www.cnblogs.com/liwenzhou/p/8296964.html Django框架的设计模式借鉴了MVC框架的思想,也是分成三部分,来降低各个部分之间 ...

  10. 2018 Multi-University Training Contest 5

    (叹气.jpg) B.Beautiful Now 题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6351 题意:给一串长度为m的数字,k次任意交换其中 ...