第一步 创建工程
File->
New->
Project->
Spring Initializr(旗舰版才有)->
Default:https://start.spring.io->
编辑Group->
编辑Artifact(唯一标示)->
一直Next到Finished
第二步 通过maven导入依赖包
项目名称右击->Maven->Reimport
第三步配置application.properties
#启动环境
spring.profiles.active=test
#端口号
server.port=8001
第四步 新加application-test.properties文件
#spring.messages.basename=i18n/message
#项目名称
spring.application.name=firstspringbootdemo
#mysql数据库驱动
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#开发环境
spring.datasource.url =jdbc:mysql://172.30.1.110:3306/hc_wiki?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=dbaccount
spring.datasource.password=P@ssw0rd99
# erp 数据源
erp.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
erp.datasource.url =jdbc:oracle:thin:@192.168.10.10:1521:JDEDB
erp.datasource.username=crpdta
erp.datasource.password=CRPDTA
第五步 配置pom.xml
<?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.example</groupId>
<artifactId>firstspringbootdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!--项目名称-->
<name>thirdspringbootdemo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<build>
<!--插件-->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.0.RELEASE</version>
<!--启动类 一定要配置-->
<configuration>
<mainClass>com.example.thirdspringbootdemo.ThirdspringbootdemoApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
配置完后重新导入Maven
第六步
如果出现下载不了的jar包,可以手动导入导本地仓库,然后clean-complier maven,重新导入maven
第七步
确保pom.xml中有spring-boot-starter-web的依赖,否则项目会启动不了