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

Springboot从入门到精通

2018-03-16 11:38 253 查看
本系列教程将持续更新Java现在最热门的框架spring boot,比起传统的springmvc,springboot无疑是更加简化了我们的开发过程。它封装了一些我们常用的配置,习惯优于配置,而且还内嵌了tomcat,大大的提高了我们的开发效率。
下面我们就从零开始搭建一个springboot项目吧。
打开我们的工具Intellij IDEA,依次点击file -->> new -->> project -->> ,然后再弹出的界面中选择jdk版本(1.8)和maven项目(注意:必须使用maven项目,因为它用到的很多依赖需要maven去为我们下载)



点击next下一步,在界面中填写父工程的artifactid和groupid和version继续下一步



选择项目存放的物理路径然后点击finish。
1.添加spring io的依赖,替我们管理版本。
打开spring的官网,https://spring.io/;选择peojects点击spring io platform项目



下拉至quick start,选择ga版(相当于稳定版)的依赖。将其复制到我们的项目中。



<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>2.添加spring cloud的依赖,替我们管理项目。
方法与上面类似,选择其中最新的GA版将依赖加入到io的下面即可



       <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR2</version>
<type>pom</type>
<scope>import&l
4000
t;/scope>
</dependency>3.修改父工程为pom工程,只做版本管理。配置maven编译插件和jdk编译版本为1.8,最终父工程的pom文件如下。<?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.cfcc</groupId>
<artifactId>cfcc-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<!--所有springboot工程都需要继承这个父工程-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>

<!-- 管理工程的版本 -->
<properties>
<cfcc.version>1.0-SNAPSHOT</cfcc.version>
</properties>

<!-- 管理版本 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>

<modules>
<module>../cfcc-core</module>
<module>../cfcc-app</module>
<module>../cfcc-browser</module>
<module>../cfcc-demo</module>
</modules>

</project>

至此我们的项目的父工程搭建完毕。下一章节将继续搭建项目的各个子模块。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: