网上关于创建Springboot项目的案例有很多,此处就不阐述,提供一个参考案例:使用IDEA创建一个springboot项目
为了方便此处将mysql、mybatis、RabbitMQ、redis、logback日志、Quartz定时任务的相关配置提前列出来,仅供参考,需要改进,可以留言评论。
server:
port: 8080
spring:
profiles:
active: dev
#mysql
datasource:
url: jdbc:mysql://ip:3306/50db
username: root
password: admin123
#
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
#Redis
redis:
database: 0
host: ip
port: 6379
password: myRedis
timeout: 3000
pool:
maxTotal : 60000
maxIdle : 300
testOnBorrow : true
#rabbitmq
rabbitmq:
host: ip
port: 5672
username: admin
password: 506304
virtual-host: /
publisher-confirms: true
publisher-returns: true
listener:
simple:
acknowledge-mode: manual
direct:
acknowledge-mode: manual
#mybatis
mybatis:
typeAliasesPackage: com.shengtong.smartlamp.entity
mapperLocations: classpath:mapping/**/*.xml
#pagehelper
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
logging:
config: classpath:env/logback.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.shengtong.smartlamp</groupId>
<artifactId>operation_center</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>operation_center</name>
<description>program project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- rabbitmq -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- redis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>17.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</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</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- quartz定时任务 -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
首先 需要安装好rabbitmq的服务器,可参考我的Centos7安装部署RabbitMQ及配置。
可参考学习:SpringBoot集成rabbitMQ
首先需要安装Redis服务,这个自行百度吧。
集成部署参考学习:springboot使用redis的配置application.yml连接池以及存取,这篇文章写的比较简陋,不过算是demo实现。
可参考学习:springboot2.0整合logback日志(详细),此篇文章还是很详细的讲解了logback打印日志机制。
可参考学习:浅谈SpringBoot集成Quartz动态定时任务,查阅了很多关于springboot集成定时任务的,大多是阐述通过配置数据源,需要创建一些quartz自身需要的数据库,我觉得这种太累赘,其实只有知道quartz动态时间配置规则,可以不那么麻烦。此篇文章就很不错。
以上集成整合,虽然参考学习别人的经验知识,但是根据自己需要,结合自己的理解,整理成自己的东西,搭建了属于自己的干净框架,也许很多地方还需要优化,后期可根据自己需要做优化。下面提供我的框架下载,希望大家多多批评指导。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。