![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
springboot
Eddie-Wang
I DO WHAT I DO.
展开
-
Maven中BOM
一、BOM简介BOM(Bill of Materials)是由Maven提供的功能,它通过定义一整套相互兼容的jar包版本集合,使用时只需要依赖该BOM文件,即可放心的使用需要的依赖jar包,且无需再指定版本号。BOM的维护方负责版本升级,并保证BOM中定义的jar包版本之间的兼容性。1.1、为什么需要BOM使用BOM除了可以方便使用者在声明依赖的客户端时不需要指定版本号外,最主要的原因是...原创 2020-04-10 16:06:01 · 899 阅读 · 0 评论 -
@PostConstruct与@PreDestroy使用示例
@PostConstruct注解用于在依赖关系注入完成之后需要执行的方法上,以执行任何初始化。@PreDestroy是用来在程序shutdown之前做一些clear up的操作。两者实现Bean初始化之前和销毁之前的自定义操作。@Componentpublic class SdkInitAndDestroyHandler{ /** * log */...原创 2019-12-26 09:46:49 · 436 阅读 · 0 评论 -
springboot + H2 单元测试遇到的问题 ([*]
通过springboot写单元测试时,遇到一个问题:Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "([*]"; expected "(, WITH, SELECT, FROM"; SQL statement:( [42001-197]从报错信息看,很明显是sql语法错误,出错位置在 ‘(’ ...原创 2019-12-19 19:46:10 · 1911 阅读 · 0 评论 -
springboot加载配置文件优先级顺序
1.springboot配置文件的加载位置1.1 springboot启动会扫描一下位置的application.properties或者application.yml作为默认的配置文件工程根目录:./config/工程根目录:./classpath:/config/classpath:/加载的优先级顺序是从上向下加载,并且所有的文件都会被加载,高优先级的内容会覆盖底优先级的内容,...原创 2019-11-20 09:41:50 · 227 阅读 · 0 评论 -
SpringBoot 使用feign时报错Service id not legal hostname
SpringBoot 使用feign时报错Service id not legal hostname(xx_sss)原因是feign不支持下划线"_",支持"-",改成xx-sss即可Does ribbon support those chars like "_" ? (Though hostname should not contain "_" , but I think it's be...原创 2019-11-19 09:37:42 · 776 阅读 · 0 评论 -
使用Spring Cloud Feign上传文件
早期的Spring Cloud中,Feign本身是没有上传文件的能力的(1年之前),要想实现这一点,需要自己去编写Encoder去实现上传。现在我们幸福了很多。因为Feign官方提供了子项目feign-form,其中实现了上传所需的Encoder。加依赖<dependency> <groupId>io.github.openfeign.form...原创 2019-11-10 10:46:26 · 373 阅读 · 0 评论 -
SpringBoot之普通类获取Spring容器中的bean
我们知道如果我们要在一个类使用spring提供的bean对象,我们需要把这个类注入到spring容器中,交给spring容器进行管理,但是在实际当中,我们往往会碰到在一个普通的Java类中,想直接使用spring提供的其他对象或者说有一些不需要交给spring管理,但是需要用到spring里的一些对象。如果这是spring框架的独立应用程序,我们通过ApplicationContextac...原创 2019-10-26 09:56:49 · 550 阅读 · 0 评论 -
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page
今天在写项目代码的时候用到了com.github.pagehelper分页插件,遇到了如下错误:java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page经过排查,发现是maven引入出错,应该引入如下:<dependency> ...原创 2019-06-27 13:30:17 · 1307 阅读 · 0 评论 -
springboot集成mybatis配置动态数据源出现连接线程数飚升的问题
最近在项目开发过程中,需要配置动态数据源,配置结束后发现数据库连接一直不断开,经过排查发现是没有配置一些参数,加上后就没有这样的问题了。@Value("${spring.datasource.url}") private String defaultDBUrl; @Value("${spring.datasource.username}") private Strin...原创 2019-06-29 11:46:54 · 2445 阅读 · 0 评论 -
Bean method 'redisTemplate' in 'RedisAutoConfiguration.RedisConfiguration' not loaded
项目开发过程中,需要整合redis,在整合过程中,出现了如下的错误:Parameter 0 of method cacheManager in org.springframework.boot.autoconfigure.cache.RedisCacheConfiguration required a bean of type 'org.springframework.data.redis....原创 2019-07-04 18:33:08 · 15565 阅读 · 4 评论 -
解决@NotBlank不生效的问题
在项目开发中,发现一个类中包含有另外一个类,这种包含关系的类上的@NotBlank校验不生效,后来发现需要在内部的类的域上加上@Valid注解,如下:/** * 标签体系ID */ @NotBlank(message = "00000002") @Length(max = 20, message = "00000005") private Stri...原创 2019-07-04 18:50:36 · 23236 阅读 · 0 评论 -
'dependencies.dependency.version' for XXX:jar is missing
今天在写项目代码调试的过程中,遇到了下列问题:[INFO] Scanning for projects...[ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] 'dependencies.dependency.version' for org.springframework.bo...原创 2019-08-08 18:32:13 · 17688 阅读 · 0 评论 -
RedisTemplate实例
@Componentpublic class RedisUtils{ /** * 日志 */ private static final Logger LOGGER = LoggerFactory.getLogger(RedisUtils.class); @Autowired private RedisTemplate redisTempl...原创 2019-08-11 10:19:41 · 1137 阅读 · 0 评论 -
springboot部署jar包读取配置文件
Spring Boot程序默认从application.properties或者application.yaml读取配置,记录下如何将配置信息外置,方便配置。方法一、通过命令行指定SpringApplication会默认将命令行选项参数转换为配置信息例如,启动时命令参数指定:java -jar myproject.jar --server.port = 9000从命令行指定配置...原创 2019-08-11 14:47:43 · 2040 阅读 · 0 评论 -
SpringBoot构造器注入循环依赖及解决
1. 循环依赖是什么?Bean A 依赖 B,Bean B 依赖 A这种情况下出现循环依赖。Bean A → Bean B → Bean A更复杂的间接依赖造成的循环依赖如下。Bean A → Bean B → Bean C → Bean D → Bean E → Bean A2. 循环依赖会产生什么结果?当Spring正在加载所有Bean时,Spring尝试以能正常创建Bean...原创 2019-08-27 19:31:22 · 2456 阅读 · 0 评论 -
Log4j.xml配置详解
AppenderAppender:日志输出器,配置日志的输出级别、输出位置等,包括以下几类:ConsoleAppender: 日志输出到控制台;FileAppender:输出到文件;RollingFileAppender:输出到文件,文件达到一定阈值时,自动备份日志文件;DailyRollingFileAppender:可定期备份日志文件,默认一天一个文件,也可设置为每分钟一个、每...原创 2019-09-03 22:28:20 · 468 阅读 · 0 评论 -
springboot文件上传之MultipartFile(图片)转base64
public ImageIdentificationResult imageIdentification(String api_id, String api_secret, MultipartFile file, String group_id) { logg...原创 2019-09-20 17:11:16 · 5514 阅读 · 0 评论 -
SpringBoot整合HttpClient
1、加入httpclient需要的jar包<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.3.1</version><...原创 2019-09-25 20:26:10 · 274 阅读 · 0 评论 -
@MapperScan注解
直接在Mapper类上面添加注解@Mapper,这种方式要求每一个mapper类都需要添加此注解,比较麻烦。通过使用@MapperScan可以指定要扫描的Mapper类的包的路径,比如:@SpringBootApplication@MapperScan("cn.test.water.monitor.mapper")// 添加对mapper包扫描public class Applic...原创 2019-09-25 20:57:34 · 445 阅读 · 0 评论 -
Spring Boot + Mybatis多数据源和动态数据源配置
多数据源首先要将spring boot自带的DataSourceAutoConfiguration禁掉,因为它会读取application.properties文件的spring.datasource.*属性并自动配置单数据源。在@SpringBootApplication注解中添加exclude属性即可:@SpringBootApplication(exclude = { ...原创 2019-04-06 13:55:57 · 210 阅读 · 0 评论 -
java连接mysql并测试是否成功,并查询当前数据库的所有数据表及对应表的字段信息
在项目开发过程中,涉及到动态配置数据源的功能,页面上配置一个新的数据源,需要在后台做验证是否可以连接,做下记录:1.获取对应数据表:/** * <数据源验证,验证成功返回对应数据库中的表名list> * * @param dataSourceCheckDTO dataSourceCheckDTO * @return 验证的数据源的表名l...原创 2019-07-01 22:12:15 · 1654 阅读 · 0 评论 -
解决java.lang.ClassNotFoundException:com.mysql.jdbc.Driver问题
在项目开发过程中,出现了这样一个问题:数据库驱动找不到,记录一下:问题现象:Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2019-07-01 19:41:42.841 ERROR 12252 --- [ ...原创 2019-07-01 22:07:11 · 1465 阅读 · 0 评论 -
springboot整合mybatis与数据库交互
Mybatis集成方式分为两种:注解版集成 XML版本集成XML版本为老式的配置集成方式,集成XML文件,SQL语句也是全部写在XML中的;注解版版本,相对来说比较简约,不需要XML配置,只需要使用注解和代码来操作数据。1、注解版 MyBatis 集成1.1 添加依赖设置pom.xml文件,添加如下配置<dependency> <groupId&...原创 2019-06-18 15:41:32 · 1121 阅读 · 0 评论 -
springboot整合quartz
简介Quartz是一款功能强大的任务调度器,可以实现较为复杂的调度功能,如每月一号执行、每天凌晨执行、每周五执行等等,还支持分布式调度。本文使用Springboot+Mybatis+Quartz实现对定时任务的增、删、改、查、启用、停用等功能。并把定时任务持久化到数据库以及支持集群。Quartz的3个基本要素1.Scheduler:调度器。所有的调度都是由它控制。2.Trigger...原创 2019-05-18 11:22:37 · 9708 阅读 · 1 评论 -
springboot启动时执行方法
Springboot给我们提供了两种“开机启动”某些方法的方式:ApplicationRunner和CommandLineRunner。在项目启动的时候立即执行某个方法:我们可以通过实现ApplicationRunner和CommandLineRunner接口来实现,他们都是在SpringApplication执行之后开始执行的。CommandLineRunner接...原创 2019-05-15 22:30:09 · 6649 阅读 · 1 评论 -
Spring boot maven项目配置文件覆盖问题
遇到这样一个问题,就是我在引用一个有application.yml的公共maven项目的时候,新maven项目的application.yml会覆盖公共项目的配置文件,SpringBoot是由上向下扫描的文件的,那么总不能其它maven的application.yml都配置文件都写一遍吧~ 如图所示:解决思路: 既然覆盖的是相同的文件名称,SpringBoot还有...原创 2019-05-10 11:03:33 · 4284 阅读 · 1 评论 -
SpringBoot——实现简单的登录认证
一、准备工作pom.xml:<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.ap...原创 2019-05-08 15:17:33 · 1635 阅读 · 0 评论 -
SpringBoot应用启动过程分析
一.应用启动类@SpringBootApplicationpublic class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}开发SpirngBoot应用时,入口类就这...原创 2019-03-27 16:07:07 · 117 阅读 · 0 评论 -
spring boot 使用@ConfigurationProperties
有这样一个场景,我们想把配置文件的信息,读取并自动封装成实体类,这样子,我们在代码里面使用就轻松方便多了,这时候,我们就可以使用@ConfigurationProperties,它可以把同类的配置信息自动封装成实体类首先在配置文件里面,相关信息如下:connection.username=adminconnection.password=kyjufskifas2jsfsconnect...原创 2019-04-05 10:28:50 · 223 阅读 · 0 评论 -
Spring Boot 最核心的 3 个注解详解
你所需具备的基础:什么是 Spring Boot? Spring Boot 核心配置文件详解 Spring Boot 开启的 2 种方式 Spring Boot 自动配置原理、实战 Spring Boot 2.x 启动全过程源码分析Spring Boot 核心注解讲解Spring Boot 最大的特点是无需 XML 配置文件,能自动扫描包路径装载并注入对象,并能做到根据 clas...原创 2019-03-05 17:45:33 · 174 阅读 · 0 评论 -
springboot项目部署到服务器
一、打包springboot为jar包:1、pom.xml 需要定义:<packaging>jar</packaging>2、如果有外部引用包,需要一起打包,pom.xml 配置如下: <resources><!-- 打包成jar发布时,才需要纳入外部包 start --> ...原创 2019-02-13 17:44:16 · 414 阅读 · 0 评论 -
springboot整合rabbitmq
RabbitMQ概念ConnectionFactory、Connection、ChannelConnectionFactory、Connection、Channel都是RabbitMQ对外提供的API中最基本的对象。Connection是RabbitMQ的socket链接,它封装了socket协议相关部分逻辑。ConnectionFactory为Connection的制造工厂。Chann...原创 2019-05-18 11:49:00 · 186 阅读 · 0 评论 -
解决Springboot @Transactional失效问题
引言对于追求数据强一致性的系统,事务扮演者十分重要的角色.最近在项目中遇到一个事务失效的问题,在此分享给大家。情景回放### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction;...原创 2019-05-23 20:01:04 · 1623 阅读 · 0 评论 -
springboot整合redis实例
1.添加依赖<!-- springboot整合 redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</a...原创 2019-06-06 14:12:09 · 1120 阅读 · 0 评论 -
Bean with name '' has been injected into other beans [] in its raw version as part of a circular ref
今天在项目编码过程中,出现了下面的异常:org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'systemService': Bean with name 'systemService' has been injected into other ...原创 2019-06-26 09:41:47 · 4267 阅读 · 0 评论 -
利用AbstractRoutingDataSource实现动态数据源切换determineCurrentLookupKey方法
首先看下AbstractRoutingDataSource类结构,继承了AbstractDataSourcepublic abstract class AbstractRoutingDataSource extends AbstractDataSource implements InitializingBean既然是AbstractDataSource,当然就是javax.sql.Dat...原创 2019-06-26 09:37:56 · 11788 阅读 · 3 评论 -
springboot事务管理详解
1、隔离级别隔离级别是指若干个并发的事务之间的隔离程度,与我们开发时候主要相关的场景包括:脏读取、重复读、幻读。我们可以看org.springframework.transaction.annotation.Isolation枚举类中定义了五个表示隔离级别的值:public enum Isolation { DEFAULT(-1), READ_UNCOMMITTED(...原创 2019-06-21 17:32:23 · 397 阅读 · 0 评论 -
springboot校验注解
Bean Validation 属性 修饰对象 校验详情 @Null 被注释的元素必须为null @NotNull 属性 属性不能为null @AssertTrue ...原创 2019-06-21 17:27:57 · 1380 阅读 · 0 评论 -
SpringBoot配置多个RabbitMQ
1.application.ymlspring: rabbitmq: hospSync: host: localhost port: 5672 username: test password: test virtual-host: test pay: host: ...原创 2019-06-04 09:57:21 · 3218 阅读 · 0 评论 -
ScheduledExecutorService指定时间定期执行某任务
@Override public void run(ApplicationArguments applicationArguments) throws Exception { long oneDay = 24 * 60 * 60 * 1000; long initDelay = getTimeMillis("02:00:00") -...原创 2019-06-04 09:54:45 · 5199 阅读 · 0 评论