包含功能

  • 阿里云消息服务MNS
  • 阿里云消息队列服务(即时消息、延迟消息、事务消息)
  • AOP日志
  • 基于MyBatis通用Mapper及DRUID的数据库访问
  • dubbo支持
  • 错误处理
  • 七牛图片服务
  • redis多连接池支持
  • swagger配置
  • 跨域配置

源码地址:https://github.com/ronwxy/base-spring-boot (如果觉得有帮助,请帮忙给个star)

主要版本

  • springboot 1.5.13.RELEASE
  • spring 4.3.17.RELEASE

1.在pom.xml文件中引入依赖管理

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.springboot.base</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.2-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

2.在pom.xml文件中引入你想要使用的starters,如

<dependency>
<groupId>com.springboot.base</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
</dependency>

3.在项目的配置文件中配置starters需要的相关配置属性

  • swagger-spring-boot-starter
    swagger:
api-description: demo for swagger api use swagger starters #api描述 如 ${spring.application.name}
api-title: demo #api标题 如 ${spring.application.name}
apis-base-package: com.example.demo.api #扫描的包名 可填根包名
group-name: demo #组名 如 ${spring.application.name}
swagger-registry-path: http://{swaggerServerIp:port}/swagger/register #swaggerapi 注册接口地址
  • tkmapper-spring-boot-starter druid数据源配置
    spring:
datasource:
druid:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://{dbServerIp:port}/db_name?charSet=UTF-8
username: dbUsername
password: dbPassword
# 自定义配置
initialSize: 2 # 初始化大小
minIdle: 1 # 最小连接
maxActive: 5 # 最大连接
druidServletSettings:
allow: 127.0.0.1
deny:
loginUsername: admin
loginPassword: Passw0rd
resetEnable: true
druidFilterSettings:
exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
maxWait: 60000 # 配置获取连接等待超时的时间
timeBetweenEvictionRunsMillis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最小生存的时间,单位是毫秒
validationQuery: SELECT 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true # 打开PSCache,并且指定每个连接上PSCache的大小
maxPoolPreparedStatementPerConnectionSize: 20
filters: stat #,wall(添加wall代码里不能直接拼接sql,druid有sql注入校验) # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
useGlobalDataSourceStat: true # 合并多个DruidDataSource的监控数据

tkmapper配置, 无默认配置

  • 自动扫描entity及mapper包,扫描路径与springboot默认路径一致

  • 扫描@Mapper

  • 自动注册com.springboot.boot.tkmapper.mapper.BaseMapper 基础接口

  • qiniu-spring-boot-starter

    qiniu:
access-key: xxx
secret-key: xxx #密钥
buckets:
- bucket-name: xxx #桶名
bucket-host: xxx #桶域名
scheme: http #协议
bucket-private: true #是否是私有桶
pipeline: imageThumbQueue #管道名
token-expired-time: 3600 #token过期时间秒
  • alimq-spring-boot-starter
    aliyun:
mq:
onsAddr: http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet #mq地址
topic: xxx #主题名称
accessKey: xxx #key
secretKey: xxx #密钥
producer: #生产者配置
enabled: true #是否开启生产者
producerId: xxx #生产者ID
consumer: #消费者配置
enabled: true #是否开启消费者
consumerId: xxx #消费者ID
tag-suffix: xxx #主题标签后缀,用来区分同一主题下不同tag
  • dubbo-spring-boot-starter
    dubbo:#dubbo zookeeper注册中心配置
zk:
registry: ip:port #注册中心zookeeper地址

用法

@Configuration
@EnableDubboProvider
@EnableDubboConsumer
public class DubboConfig{ }
  • aoplog-spring-boot-starter 没有配置

  • error-spring-boot-starter

    • 没有配置
    • 提供默认的全局异常处理器com.springboot.boot.error.exception.ExceptionHandlerAutoConfiguration$DefaultGlobalExceptionHandler
  • alimns-spring-boot-starter

   mns:
access-id: xxx
access-key: xxx
account-endpoint: xxx
  • redisclient-spring-boot-starter
    spring:
redis:
host: ip
database: 1
redis:
clients:
db1:
host: ip
database: 2
clients-enabled: true #是否开启多个客户端
    @Configuration
@RedisClient("db1")//除了默认的连接池会实例化另一个连接池
public class ConfigClass{
@Bean
public RedisTokenStore getRedisTokenStore(RedisClientFactory factory){
//获取db1的连接池
RedisConnectionFactory connectionFactory = factory.getInstance("db1",RedisConnectionFactory.class);
return new RedisTokenStore(connectionFactory);
}
}

排除自动配置示例

    @SpringBootApplication(exclude = Swagger2AutoConfiguration.class)
public class TestApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(TestApplication.class).run(args);
}
}

Sping Boot入门到实战之实战篇(二):一些常用功能的Spring Boot Starters的更多相关文章

  1. Spring Boot 入门之缓存和 NoSQL 篇(四)

    原文地址:Spring Boot 入门之缓存和 NoSQL 篇(四) 博客地址:http://www.extlight.com 一.前言 当系统的访问量增大时,相应的数据库的性能就逐渐下降.但是,大多 ...

  2. 43. Spring Boot动态数据源(多数据源自动切换)【从零开始学Spring Boot】

    [视频&交流平台] àSpringBoot视频 http://study.163.com/course/introduction.htm?courseId=1004329008&utm ...

  3. (43). Spring Boot动态数据源(多数据源自动切换)【从零开始学Spring Boot】

    在上一篇我们介绍了多数据源,但是我们会发现在实际中我们很少直接获取数据源对象进行操作,我们常用的是jdbcTemplate或者是jpa进行操作数据库.那么这一节我们将要介绍怎么进行多数据源动态切换.添 ...

  4. Sping Boot入门到实战之入门篇(二):第一个Spring Boot应用

    该篇为Spring Boot入门到实战系列入门篇的第二篇.介绍创建Spring Boot应用的几种方法. Spring Boot应用可以通过如下三种方法创建: 通过 https://start.spr ...

  5. Spring Boot Freemarker特别篇之contextPath【从零开始学Spring Boot】(转)

    需求缘起:有人在群里@我:请教群主大神一个问题,spring boot  + freemarker 怎么获取contextPath 头疼死我了,网上没一个靠谱的 .我就看看之前博客中的 [Spring ...

  6. Spring Boot Freemarker特别篇之contextPath【从零开始学Spring Boot

      需求缘起:有人在群里@我:请教群主大神一个问题,spring boot  + freemarker 怎么获取contextPath 头疼死我了,网上没一个靠谱的 .我就看看之前博客中的 [Spri ...

  7. 24. Spring Boot环境变量读取和属性对象的绑定【从零开始学Spring Boot】

    转:http://blog.csdn.net/linxingliang/article/details/52069509 凡是被spring管理的类,实现接口EnvironmentAware 重写方法 ...

  8. (24)Spring Boot环境变量读取和属性对象的绑定【从零开始学Spring Boot】

    凡是被Spring管理的类,实现接口 EnvironmentAware 重写方法 setEnvironment 可以在工程启动时,获取到系统环境变量和application配置文件中的变量. com. ...

  9. spring boot:方法中使用try...catch导致@Transactional事务无效的解决(spring boot 2.3.4)

    一,方法中使用try...catch导致@Transactional事务无效的解决方法 1,问题的描述: 如果一个方法添加了@Transactional注解声明事务, 而方法内又使用了try catc ...

随机推荐

  1. UltraEdit快捷键大全-UltraEdit常用快捷键大全

    UltraEdit快捷键大全-UltraEdit常用快捷键大全 UltraEdit是一套功能强大的文本编辑器,可以编辑文本.十六进制.ASCII码,可以取代记事本,内建英文单字检查.C++及VB指令突 ...

  2. POJ3170 Bzoj1671 [Usaco2005 Dec]Knights of Ni 骑士

    1671: [Usaco2005 Dec]Knights of Ni 骑士 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 281  Solved: 180 ...

  3. 使用python将ppm格式转换成jpg【转】

    转自:http://blog.csdn.net/hitbeauty/article/details/48465017 最近有个很火的文章,叫 有没有一段代码,让你觉得人类的智慧也可以璀璨无比? 自己试 ...

  4. android中提示&对话框----Toast

    Toast(吐司) 一.Toast吐司是一种消息提示框,在手机屏幕中显示一个消息提示框,没有任何按钮,也不会获得焦点,一段时间后自动消失,常常在调试的时候用的较多. 二.使用 (1)直接调用Toast ...

  5. maven更换阿里云仓库

    本来不想写,网上到处都是,不过好多到我这不行,自己记录下,省的到处找 D:\apache-maven-3.6.1\conf目录下setting.xml文件(这是我的解压的位置) <mirrors ...

  6. 在 IntelliJ IDEA 中配置 JSF 开发环境的入门详解

    JSF 作为 JavaEE 官方标准,在了解并掌握其基本开发技术后,对于功能要求较高.业务流程复杂的各种现代 Web 应用程序开发将会成为非常合适且强大的高效率开发利器.JSF 的开发环境搭建涉及到在 ...

  7. ios圆角优化-不掉帧

    因网络图片加载用的是SDWebImage所以下面以sd加载图片为例 //普通的加载网络图片方式(已不能满足需求,需要改进) [self sd_setImageWithURL:url placehold ...

  8. K均值聚类(C++)

    #include<math.h> #include<stdio.h> #include<stdlib.h> #include<iostream> usi ...

  9. 4C 2018 福到了

    输入字符c(只含有@和空格).数字n.规模n*n的二维字符矩阵. 若倒过来的数组和原数组一样形式输出提示. 最后输出以字符c替换的字符数组. #include <bits/stdc++.h> ...

  10. cogs——1008. 贪婪大陆(清华巨佬代码)——树状数组

    1008. 贪婪大陆 ★★   输入文件:greedisland.in   输出文件:greedisland.out   简单对比时间限制:1 s   内存限制:128 MB 试题四:贪婪大陆  [题 ...