记录IDEA的各种坑
- 一、IDEA导致项目无法运行的bug
- 二、第三方对接的bug
- 三、关于jar包冲突的bug
- 1、com.alibaba.excel.exception.ExcelAnalysisException: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic
- 2、An attempt was made to call a method that does not exist. The attempt was made from the following location: com.google.common.cache.CacheBuilder.maximumSize(CacheBuilder.java:435)
一、IDEA导致项目无法运行的bug
1、Failed to determine a suitable driver class
异常背景:
数据源配置正确、jar包无冲突、“上一次还能运行,这一次确不行”等。异常信息:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
原因分析:
IDEA打包时没有复制属性文件到target目录
错误示例:
正确示例:
解决方案:
执行 build > rebuild project; 随后[重启项目]
2、resources没加载为资源目录 或 Module ‘xxx’ is imported from Maven.Any changes made in its configuration may be lost after reimporting.
异常背景:
打开项目resources目录没有加载为资源目录。且自主设置报错。异常信息:
Module 'xxx' is imported from Maven.Any changes made in its configuration may be lost after reimporting.
原因分析:
资源项目为子module或因缓存问题IDEA未正确应用JDK
错误示例:
正确示例:
解决方案:
依次点击 File -> Project Structure -> Project 检查JDK 和下方 language level是否一致,如果一致尝试重新选择当前JDK版本,如果最下方Apply按钮变得可以点击则说明是IDEA缓存问题,点击Apply按钮即可。如果自己设置resources报错Module ‘xxx’ is imported from Maven.Any changes made in its configuration may be lost after reimporting。也是解决方案。
检查JDK 和下方 language level是否一致,如果一致尝试重新选择当前JDK版。
如果Apply按钮变得可以点击则说明是IDEA缓存问题,点击Apply按钮即可。
如果走到一步仍然没有正确识别,那么点击Project下方的Modules按钮。选择资源目录点击设置为Resoutrces并点击Apply按钮。
二、第三方对接的bug
1、No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
异常背景:
微信支付 - 申请退款报错异常信息:
No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
原因分析:
微信支付退款功能使用的协议被JDK禁用
解决方案:
1、更换对应版本JDK【强烈不推荐】
2、手动修改微信代码,不主动使用协议如:TLSv1
3、修改【JDK/JRE】配置文件:
如果是OPEN JDK需求修改 /etc/crypto-policies/back-ends/java.config 文件
如果是Oracle JDK需求修改【JDK/JRE】/lib/security/java.security 文件
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
include jdk.disabled.namedCurves
-- 移除被禁止的协议,如:TLSv1
三、关于jar包冲突的bug
1、com.alibaba.excel.exception.ExcelAnalysisException: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic
异常背景:
项目同时集成【easyexcel】 和 【org.apache.poi.xwpf.converter.pdf】或其它需要使用到【poi-ooxml】将word转为pdf的工具时word转pdf正常运行时【easyexcel】使用InputStream解析excel会报错异常信息:
com.alibaba.excel.exception.ExcelAnalysisException: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic
at com.alibaba.excel.analysis.ExcelAnalyserImpl.<init>(ExcelAnalyserImpl.java:57)
at com.alibaba.excel.ExcelReader.<init>(ExcelReader.java:145)
at com.alibaba.excel.read.builder.ExcelReaderBuilder.build(ExcelReaderBuilder.java:193)
at com.alibaba.excel.read.builder.ExcelReaderBuilder.sheet(ExcelReaderBuilder.java:229)
at com.alibaba.excel.read.builder.ExcelReaderBuilder.sheet(ExcelReaderBuilder.java:221)
at com.liheng.nursing.excel.utils.ExcelUtil.readSheet(ExcelUtil.java:110)
at com.liheng.nursing.basic.service.lead.impl.ImportWaterElectricityServiceImpl.analysis(ImportWaterElectricityServiceImpl.java:64)
at com.liheng.nursing.basic.service.lead.impl.ImportWaterElectricityServiceImpl$$FastClassBySpringCGLIB$$83fe6dff.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
at com.liheng.nursing.basic.service.lead.impl.ImportWaterElectricityServiceImpl$$EnhancerBySpringCGLIB$$349ae00.analysis(<generated>)
at com.liheng.nursing.basic.service.impl.ImportServiceImpl.lambda$reload$3(ImportServiceImpl.java:237)
at com.liheng.nursing.utils.RedisUtil.executeAndLock(RedisUtil.java:991)
at com.liheng.nursing.utils.RedisUtil.executeAndLock(RedisUtil.java:1037)
at com.liheng.nursing.basic.service.impl.ImportServiceImpl.reload(ImportServiceImpl.java:228)
at com.liheng.nursing.basic.service.impl.ImportServiceImpl$$FastClassBySpringCGLIB$$53f5e2bd.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
at com.liheng.nursing.basic.service.impl.ImportServiceImpl$$EnhancerBySpringCGLIB$$ace7f2fa.reload(<generated>)
at com.liheng.nursing.basic.controller.ImportController.reload(ImportController.java:74)
at com.liheng.nursing.basic.controller.ImportController$$FastClassBySpringCGLIB$$756e5651.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
at com.liheng.nursing.basic.aop.LogAspect.logAround(LogAspect.java:61)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
at com.liheng.nursing.basic.controller.ImportController$$EnhancerBySpringCGLIB$$4ef5318c.reload(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:920)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.github.xiaoymin.knife4j.spring.filter.SecurityBasicAuthFilter.doFilter(SecurityBasicAuthFilter.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.liheng.nursing.wps.config.CorsFilter.doFilter(CorsFilter.java:26)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic
at com.alibaba.excel.support.ExcelTypeEnum.recognitionExcelType(ExcelTypeEnum.java:90)
at com.alibaba.excel.support.ExcelTypeEnum.valueOf(ExcelTypeEnum.java:78)
at com.alibaba.excel.analysis.ExcelAnalyserImpl.choiceExcelExecutor(ExcelAnalyserImpl.java:62)
at com.alibaba.excel.analysis.ExcelAnalyserImpl.<init>(ExcelAnalyserImpl.java:51)
... 113 more
Caused by: java.lang.ClassNotFoundException: org.apache.poi.poifs.filesystem.FileMagic
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 117 more
原因分析:
项目同时集成【easyexcel】 和 【org.apache.poi.xwpf.converter.pdf】或其它需要使用到【poi-ooxml】将word转为pdf的工具时、大部分工具使用的都是低版本的【poi-ooxml】且无法升级为版本。升级后高版本后转换工具会报错Loggers相关报错,高版本Loggers相关与低版本设计不同,一个为类,一个为接口。但低版本【poi-ooxml】会导致【easyexcel】通过InputStream
解决方案:
1、直接使用File文件读取或把InputStream转为File读取
2、An attempt was made to call a method that does not exist. The attempt was made from the following location: com.google.common.cache.CacheBuilder.maximumSize(CacheBuilder.java:435)
异常背景:
Spring Cloud 项目移除consul后启动失败异常信息:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.google.common.cache.CacheBuilder.maximumSize(CacheBuilder.java:435)
The following method did not exist:
com.google.common.base.Preconditions.checkState(ZLjava/lang/String;J)V
The method's class, com.google.common.base.Preconditions, is available from the following locations:
jar:file:/E:/repositorys/com/google/collections/google-collections/1.0/google-collections-1.0.jar!/com/google/common/base/Preconditions.class
jar:file:/E:/repositorys/com/google/guava/guava/28.2-android/guava-28.2-android.jar!/com/google/common/base/Preconditions.class
It was loaded from the following location:
file:/E:/repositorys/com/google/collections/google-collections/1.0/google-collections-1.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.common.base.Preconditions
原因分析:
jar包冲突、consul中存在忽略或限制google-collections-1.0.jar注入的条件,或consul存在控制guava版本代码
解决方案:
1、通过idea自带工具检查依赖、找出引用的jar包做依赖排除
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>
或
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>