![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
springboot
qq_34412985
Coding make me happy.
展开
-
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized t
spring的controller接口@RequestBody传入form表单报以下错误:org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized token 'cpId': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.Json.原创 2022-05-24 14:30:50 · 9955 阅读 · 0 评论 -
记一次springboot中controller为抽象的导致请求不了该地址
spring中使用controller类是抽象的,然后导致该controller不能正常映射成请求的端口暴露出去原创 2021-11-24 21:20:50 · 542 阅读 · 0 评论 -
springboot2.1.0版本导致数据库连接不写driver名称和字符集报错
默认是可以不写driver-class-name,utf8和utf-8都是识别的但有些版本是不支持的,如果检查后没有其他问题时,可以检查是否因为版本导致的这些问题原创 2021-11-21 14:07:47 · 829 阅读 · 0 评论 -
如何排除掉maven引入的jar包里的某个类
我遇到的问题是工程中引入Inceptor.jar包后报错,如何排除掉maven引入的jar包里的HttpHost类冲突导致,jar:file:/D:/work/maven_repository/com/pc/inceptor/1.0/inceptor-1.0.jar!/org/apache/http/HttpHost.class jar:file:/D:/work/maven_repository/org/apache/httpcomponents/httpcore/4.4.13/httpcor...原创 2021-10-15 20:00:04 · 8476 阅读 · 1 评论 -
在service构造方法中用ApplicationContext获取bean报NullPointerException错
// @PostConstruct// public void setMetaColGatherDao() {// if(metaColGatherDao == null) {// metaColGatherDao = SpringContextUtil.getBean(MetaColGatherDao.class);// }// System.out.println("我是测试启动类DataCon...原创 2021-05-29 17:03:17 · 1240 阅读 · 0 评论 -
Spring boot项目设置静态资源(spring.resources.static-locations)
默认Springboot将从如下位置按如下优先级(从高到低)加载jar包对应前端静态资源:1.jar包同级static目录2.jar包同级public目录3.jar包同级resource目录4.jar包/META-INF/resources在调试模式下,Springboot将从class目录中按如下优先级(从高到低)加载对应前端静态资源1.class目录下static目录2.class目录下public目录3.class目录下resource目录4.class目录下/META-INF/原创 2021-05-15 18:25:51 · 1586 阅读 · 0 评论 -
SpringBoot项目连接ElasticSearch时报错:None of the configured nodes are available
问题描述:在springboot项目中使用TransportClient方式连接ES,完整报错:org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available背景 SpringBoot版本:1.5.11 ES版本:7.0.0 项目中配置文件:spring.data.elasticsearch.cluster-name=ela...原创 2021-04-08 19:24:36 · 392 阅读 · 0 评论 -
zuul学习二:zuul路由详解(一)
传统路由配置所谓的传统路由配置方式就是在不依赖与服务发现机制的情况下,通过在配置文件中具体制定每个路由表达式实例的映射关系来实现api网关对外部请求的路由。没有Eureka等服务治理框架的帮助,我们需要根据服务实例的数量采用不同方式的配置来实现路由规则:单实例配置:通过zuul.routes.<route>.path与zuul.routes.<route>.url参数对的方式进行配置,比如:...转载 2021-03-29 14:28:12 · 181 阅读 · 0 评论 -
springboot2.X引入actuator依赖无法查看endpoint
springboot1.X中引入actuator依赖后我们就可以通过对应的endpoint查看与应用相关的信息,springboot2.X以后需进行如下配置才可访问:management: endpoints: web: base-path: /actuator exposure: include: "*"在springboot2.x的application.properties文件中单独暴露management.endpoints.web...原创 2021-03-29 13:35:36 · 307 阅读 · 0 评论 -
spring的@Autowired注入无法实例化service问题解决(继承netty的simpleInbountHandler处理类后无法实例化service)
首先目前我写的项目是springboot+netty,在接收客户端传输的数据时调用service一直报null指针异常 刚开始没有想到是service无法实例化的问题,一直在测试数据方面的问题,后来去群里讨论才知道问题所在 我这里讲的netty接收数据的handler类,但是基本都大同小异 如果我们直接在一个不是controller类的里面注入@Autowired的时候,而且还去调用就会报null指针像这样如果直接调用的话就会报错下面来说怎么解决首先需要了解两个注解 @Co...原创 2021-03-26 16:06:45 · 750 阅读 · 0 评论 -
springboot修改bean的生成规则
public class UniqueNameGenerator extends AnnotationBeanNameGenerator { @Override public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) { //全限定类名 String beanName = definition.getBeanClassName();...原创 2021-01-31 15:39:56 · 731 阅读 · 0 评论 -
spring注入map,spring注入一个接口的多个实现类在map里
一个接口,两个实现类接口:public interface TestService { void test();}两个实现类@Component("testOService")public class TestOService implements TestService { @Override public void test() { System.out.println("testOService"); }}..原创 2021-01-28 22:00:04 · 753 阅读 · 0 评论 -
Spring注解的(List&Map)特殊注入功能
今天偶然在网页留言上发现,有人说用@Autowired可以注入bean到声明的map中,当时我还不信,怎么可能呢,@Autowired只用过向定义的类型中注入bean,map跟bean非亲非故,怎么会注入那些实例,于是试验了一下,果然灵验@Autowiredprivate Map<String, BizService> map = new HashMap<>();// 向map中注入所有类型为BizService类型的bean,其中键为bean的名称,值为bean的实例原创 2021-01-28 18:28:42 · 1063 阅读 · 0 评论 -
springboot+security 的BCryptPasswordEncoder 使用
任何应用考虑到安全,绝不能明文的方式保存密码。密码应该通过哈希算法进行加密。有很多标准的算法比如SHA或者MD5,结合salt(盐)是一个不错的选择。 Spring Security 提供了BCryptPasswordEncoder类,实现Spring的PasswordEncoder接口使用BCrypt强哈希方法来加密密码。BCrypt强哈希方法 每次加密的结果都不一样。好了废话不多说,就看怎么整合吧。。1. 修改 WebSecurityConfig @Autowired p原创 2021-01-10 18:04:26 · 438 阅读 · 0 评论 -
Correct the classpath of your application so that it contains a single, compatible version of xxx
Correct the classpath of your application so that it contains a single, comp是因为activiti5.22中引入的mybatis版本和springboot中引入的不一致导致的Spring Boot 启动报如题错误,这种情况是依赖版本的问题引起,一个个依赖排除就可以了。pom.xml把全部依赖注释掉,然后一个个加进去并试启动,最后肯定能找到出问题的那个依赖...原创 2020-10-09 19:10:23 · 2390 阅读 · 0 评论 -
错误:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String
最近刚刚开始用SpringBoot做项目,之前项目跑得好好的,就启动不起来了,后来终于解决了这个错误,这种错误出现原因很多吧,我这只能算一种原因。 直接进入正题,我遇到的导致出现这个报错的原因:maven项目中引入了多个版本的servlet-api的jar包,项目加载时候加载错了类(加载到servlet-api包中的类),getVirtualServerName我只在SpringBoot内嵌的Tomcat的包里见到了! 解决方案:Servlet-api 3.1.0以及之后的版本中才有ge...原创 2020-09-10 23:04:42 · 1789 阅读 · 0 评论 -
上传文件的输出日志信息
2020-09-01 15:43:29.809 INFO com.pc.data.governance.aop.ControllerAopWithBdap Line:61 - 请求路径是===>>>/standardMapping/uploadData请求方法是===>>>public java.lang.Object com.pc.data.ds.controller.StandardMappingUploadAndDownloadController.upload..原创 2020-09-10 17:30:44 · 2391 阅读 · 0 评论 -
[SpringCloud] SpringCloud微服务实战 导入hystrix找不到@HystrixCommand问题
作者是使用的就老版本的SpringBoot+SpringCloud, 导入的依赖是: <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> 对于Spring Boot 2.0+Spring Cloud Finc...转载 2020-09-03 22:50:55 · 503 阅读 · 0 评论 -
Zuul超时问题,微服务响应超时,zuul进行熔断
是这样的,今天碰到了微服务响应超时问题,而且超时时间特别短,2秒就超时,zuul就走熔断了。我采用zuul作为网关,根据不同的访问路径进行微服务的路由,譬如有个服务是user,我访问user服务的某个接口时,该接口执行时间很慢,2秒多,然后还没执行完,zuul就执行熔断了,进入了我配好的ZuulFallbackProvider里。所以来研究一下zuul的超时处理。前提,zuul和微服务都已经注册到了eureka中,zuul采用service-id来进行路由,当访问/user时进入到user服务中。而且,转载 2020-09-02 17:31:01 · 398 阅读 · 0 评论 -
Spring boot CommandLineRunner接口使用例子
阅读目录前言 如何使用CommandLineRunner接口 用@Order注解去设置多个CommandLineRunner实现类的执行顺序 为什么要使用CommandLineRunner接口 原文文链前言Spring boot的CommandLineRunner接口主要用于实现在应用初始化后,去执行一段代码块逻辑,这段初始化代码在整个应用生命周期内只会执行一次。如何使用CommandLineRunner接口我们可以用以下三种方式去使用CommandLineRunner接口转载 2020-09-01 23:07:11 · 130 阅读 · 0 评论 -
解决No thread-bound request found: Are you referring to request attributes outside of an actual web re
使用背景:今天在spring-cloud项目中,使用多线程异步调用微服务出现的错误Nothread-boundrequestfound:Areyoureferringtorequestattributesoutsideofanactualwebrequest,orprocessingarequestoutsideoftheoriginallyreceivingthread?Ifyouareactuallyoperatingwithina...原创 2020-08-30 21:24:39 · 1029 阅读 · 0 评论 -
feign method GET must not have a request body.超过2个参数时报Method has too many Body parameters:
feign使用okhttp3的Get方式请求接口时必须加@RequestParam,否则会报错feign method GET must not have a request body,name传入null值也会报错public Object getParamsByAppCode(@RequestParam(value = "appCode") String appCode,@RequestParam(value = "name",required=false) String name);...原创 2020-08-22 22:52:55 · 7545 阅读 · 1 评论 -
记录一次jdk编译版本不一致导致springAop和bean找不到和springboot版本不一致导致的跨系统调用时ribbon time out
老项目编译jar包时使用的JDK7,主分支合并一些新功能和fix bug,需要将主分支合并到项目分支上后做更新,这时候刚刚接手不清楚原来使用JDK7还是JDK8编译,默认以为是JDK8编译文件,所以使用JDK8编译文件后,项目启动报classNot Found和请求接口时原来的调用没生效,metaSearchService没找到,metaSearchService接口没生效,后来使用JDK编译后恢复正常。项目中common-node引用springboot2.0.9,同时引用common-bean引用s原创 2020-08-21 08:31:21 · 226 阅读 · 0 评论 -
springboot项目启动时报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded
2020-08-02 10:33:27.322 WARN 9560 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Using default backup registry implementation which does not do anything.2020-08-02 10:33:27.322 INFO 9560 --- [ restartedMain] com.netflix.discovery.Disc...原创 2020-08-02 12:39:39 · 871 阅读 · 0 评论 -
springcloud项目中eureka-server、eureka-client、config-server、zuul互相如何通信请求
auth服务在bootstrap.yml中没有指定eureka-server的ip和port,config-file中application.properties中指定eureka-server的ip和port是localhost:8761或者没有指定时,默认就是localhost:8761;这样auth服务从eureka-server上通过bootstrap.yml配置的spring.cloud.config.serviceId去找config-server,如果找到后去加载bootstrap.yml配置原创 2020-08-02 12:38:08 · 315 阅读 · 0 评论 -
WebSocket之ServerEndPoint
WebSocket是JavaEE7新支持的:The javax.websocket.server package contains annotations, classes,and interfaces to create and configure server endpoints.Javax.websocket.server包含注解,类,接口用于创建和配置服务端点The javax.websocket package contains annotations, classes,...原创 2020-08-01 22:36:53 · 1783 阅读 · 0 评论 -
记一次druid连接池配置问题引发服务假死的定位、分析、解决过程
一、前言 记录一次服务假死的整个排查过程,服务基础为spring boot + druid + 多数据源切换,在请求过多(尤其是长事务请求)时,服务出现请求无响应的状况,之前未完结的查询也没有任何返回结果。二、定位问题原因 问题出现时,表现如下图,后台无任何报错,sql语句戛然而止,后续的查询被中断。这时如果再次发起某个请求,后台服务处于大部分时间不能收到新的请求的状态,或者偶尔可收到请求但不会执行crud。经过一段时间后,日志输出了session校验的内容,此时我推...转载 2020-08-01 16:19:41 · 2696 阅读 · 0 评论 -
手动创建DruidDataSource失败后死循环以及程序卡住的问题
druid的版本:1.1.20这个问题在druid的github源码上一直是个open的issue,见3488和3357等druid的配置,注意timeBetweenEvictionRunsMillis参数,这是造成卡的原因。这个参默认值为60 * 1000L(60秒),单位是毫秒# Druid配置spring.datasource.druid.initial-size=5spring.datasource.druid.min-idle=5spring.datasource.druid.转载 2020-08-01 16:16:54 · 4060 阅读 · 5 评论 -
Spring学习笔记 根据部署环境加载bean
1.引言在开发过程中遇到的一大挑战就是将应用程序从一个环境部署到另一个环境,Spring为环境相关的bean提供了很好的解决方案。在这个过程中Spring会根据环境决定该创建哪个bean和不创建哪个bean。不过Spring并不是在构建的时候做出这样的决策,而是等到运行时再来确定。这样的结果就是同一个部署单元(可能是WAR文件)能够适用于所有的环境,没有必要进行重新构建。2.配置profile bean在3.1版本,Spring引入了bean profile的功能。在Java配置中,可以使用@原创 2020-08-01 16:15:14 · 891 阅读 · 0 评论 -
springboot项目中访问druid内置监控页面
1、首先加入druid依赖<dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.9</version> </dependency>2、设置配置文件:# 数据库访问配置# 主数据源,默认的spring.datasource..原创 2020-08-01 15:42:32 · 742 阅读 · 0 评论 -
【枚举工具类】EnumUtils
EnumUtils 介绍一、官方API地址官网地址:EnumUtils.html二、EnumUtils 常用API1.导入POM文件这里使用的是:3.9 的版本,还是比较新的 <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> ...原创 2020-08-01 14:28:30 · 2874 阅读 · 0 评论 -
SpringBoot使用@Async注解失效分析(@Transactional事务注解失效分析)
有时候在使用的过程中@Async注解会失效(原因和@Transactional注解有时候会失效的原因一样)。下面定义一个Service:两个异步执行的方法test03()和test02()用来模拟项目中可能出现的耗时的操作,然后test()方法调用这两个耗时的方法:定义Controller:执行方法,返回结果:方法执行结果明显与我们的预期不符,方法的输出顺序表示了test02()和test03()两个异步方法居然同步执行了,也就是说@Aysnc注解失效了!失效的原因是因为转载 2020-07-30 17:56:49 · 884 阅读 · 0 评论 -
springboot中自定义线程池初始化时候coreSize大于maxPoolSize导致程序启动报错如下
2020-07-28 15:45:08,707 INFO [main] AnnotationConfigApplicationContext: Closing FeignContext-system-param-service-node: startup date [Tue Jul 28 15:45:07 CST 2020]; parent: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerAppli原创 2020-07-29 17:13:58 · 1662 阅读 · 0 评论 -
修改Spring自定义异步线程池的错误
@EnableAsync@Configurationpublic class AsyncTaskExecutePoolConfig implements AsyncConfigurer {public static final int CORE_POOL_SIZE = 20;private static final int MAX_POOL_SIZE = 50;private static final int QUEUE_CAPACITY = 100;private static final转载 2020-07-28 19:56:36 · 1135 阅读 · 0 评论 -
springboot做maven聚合工程的父工程的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.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersio..原创 2020-07-25 22:06:19 · 443 阅读 · 0 评论 -
org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionSta
org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope异常处理springboot的主启动类上不需要加@EnableTransactionManagement这个注解1.业务场景 在一段数据库操作中添加了事务注解@Transactional(rollbackFor = Exception.class),但是代码中有try ca.原创 2020-07-14 17:38:57 · 2231 阅读 · 0 评论 -
docker安装oracle11gR2连接时报ORA-12516或12520错误的处理
解决过程:1、查看当前会话数、processes和sessions值,发现session数和2个参数的值已经非常逼近SQL*Plus:Release10.2.0.1.0-Productionon星期一10月915:50:212006Copyright(c)1982,2005,Oracle.Allrightsreserved.SQL>conn/assysdba已连接。SQL>selectcount(*)fromv$session;COUNT...原创 2020-07-03 00:03:31 · 433 阅读 · 0 评论 -
SpringBoot启动报错:LoggerFactory is not a Logback LoggerContext but Logback is on the classpath
这个问题是slf4j包冲突所产生的问题,本博调试过程借鉴了下面链接所述博客,但情况与其不尽相同,博客将通过两种方式进行包的排除。https://juejin.im/entry/5b6927906fb9a04fb900f611目录一、日志信息及错误二、编辑pom.xml文件进行包的调整三、直接在IDEA依赖图中进行修改一、日志信息及错误1、完整日志SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding i转载 2020-06-16 22:23:10 · 19384 阅读 · 2 评论 -
关于在rc.local中放入Java程序无法开机自启的问题
今天公司服务器因为断电重启发现了一个问题——所有部署了springboot打的jar包的服务器在重启后没有自动将服务启动起来。但是rc.local文件是有可执行权限的,而且单独执行该文件中的条目可以正常启动服务,那么问题会在哪里呢?在jar启动脚本后面加上了重定向生成一个启动日志或者通过ps -ef|grep jar查进程看看:1/usr/local/bin/tomcat/bin/startup.sh>>/tmp/startup.log结果发现日志提示找不到环境变量JAVA_HOME,但是原创 2020-06-13 17:32:29 · 1901 阅读 · 0 评论 -
springboot借助maven插件system path,加载本地jar
当引用第三方包,且没有源代码时候,可以使用system path<dependency> <groupId>ctec</groupId> <artifactId>xxx-core</artifactId> <version>1.0</version> <scope>system</scope> <systemPath>${project.b原创 2020-06-09 22:05:24 · 2235 阅读 · 0 评论