记录IDEA的各种坑

  • 一、IDEA导致项目无法运行的bug
  • 1、Failed to determine a suitable driver class
  • 异常背景:
  • 异常信息:
  • 原因分析:
  • 解决方案:
  • 2、resources没加载为资源目录 或 Module 'xxx' is imported from Maven.Any changes made in its configuration may be lost after reimporting.
  • 异常背景:
  • 异常信息:
  • 原因分析:
  • 解决方案:
  • 二、第三方对接的bug
  • 1、No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
  • 异常背景:
  • 异常信息:
  • 原因分析:
  • 解决方案:
  • 三、关于jar包冲突的bug
  • 1、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目录

错误示例:

Java项目遗留问题 java实际项目中遇到的问题_Java项目遗留问题


正确示例:

Java项目遗留问题 java实际项目中遇到的问题_java_02


解决方案:

执行 build > rebuild project; 随后[重启项目]

Java项目遗留问题 java实际项目中遇到的问题_java_03


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

错误示例:

Java项目遗留问题 java实际项目中遇到的问题_intellij-idea_04

Java项目遗留问题 java实际项目中遇到的问题_解决方案_05

正确示例:

Java项目遗留问题 java实际项目中遇到的问题_java_06


解决方案:

依次点击 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。也是解决方案。

Java项目遗留问题 java实际项目中遇到的问题_intellij-idea_07


检查JDK 和下方 language level是否一致,如果一致尝试重新选择当前JDK版。

Java项目遗留问题 java实际项目中遇到的问题_Java项目遗留问题_08


如果Apply按钮变得可以点击则说明是IDEA缓存问题,点击Apply按钮即可。

Java项目遗留问题 java实际项目中遇到的问题_解决方案_09


如果走到一步仍然没有正确识别,那么点击Project下方的Modules按钮。选择资源目录点击设置为Resoutrces并点击Apply按钮。

Java项目遗留问题 java实际项目中遇到的问题_解决方案_10


二、第三方对接的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、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包做依赖排除

Java项目遗留问题 java实际项目中遇到的问题_java_11


Java项目遗留问题 java实际项目中遇到的问题_解决方案_12

<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>