一、创建
1、开始创建
2、选择spring Initializr
3、修改Group和Artifact
4、选择版本及相关组件
5、更改项目名字和项目地址
6、删除多余部分
二、配本地maven
三、更改合适的版本
一直使用2.0.4.RELEASE版本,其他版本有时候会出现数据库不兼容报错的现象。
四、引入常用的pom配置
1、常用配置
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.1.8.RELEASE</version>
</dependency>
<!--kafka-clients发送消息所需jar包-->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<!-- orcale驱动 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>12.1.0.1-atlassian-hosted</version>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
2、引入打包插件
<build>
<finalName>mytest-1.0.0</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
五、将application.properties放到src同级
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.resources.static-locations=classpath:static/,file:static/
server.port=8094
spring.message.encoding=UTF-8
spring.mvc.view.prefix=/templates/
spring.mvc.view.suffix=.html
#oracle
spring.datasource.url=jdbc:oracle:thin:@192.168.x.x:1521:orcl
spring.datasource.username=myname
spring.datasource.password=mypwd
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
# kafka
spring.kafka.bootstrap-servers=192.168.x.xx:6667,192.168.x.xx:6667,192.168.x.xx:6667
#spring.kafka.consumer.group-id=consumeGroup14444
spring.kafka.consumer.group-id=21
spring.kafka.consumer.auto-offset-reset=earliest