java 重新加载spring_SpringBoot的reload加载器的方法

背景

出现了相同类castException

分析

首先确定出现相同类的castException比如是由于classloader不同造成的。

一个class是否相同取决于两个因素

classloader相同

class文件相同

即不同classloader解释出来的class是不同的class

我们在学习jdbc的时候常见的使用

/**

* Returns the {@code Class} object associated with the class or

* interface with the given string name. Invoking this method is

* equivalent to:

*

*

* {@code Class.forName(className, true, currentLoader)}

*

*

* where {@code currentLoader} denotes the defining class loader of

* the current class.

*

*

For example, the following code fragment returns the

* runtime {@code Class} descriptor for the class named

* {@code java.lang.Thread}:

*

*

* {@code Class t = Class.forName("java.lang.Thread")}

*

*

* A call to {@code forName("X")} causes the class named

* {@code X} to be initialized.

*

* @param className the fully qualified name of the desired class.

* @return the {@code Class} object for the class with the

* specified name.

* @exception LinkageError if the linkage fails

* @exception ExceptionInInitializerError if the initialization provoked

* by this method fails

* @exception ClassNotFoundException if the class cannot be located

*/

public static Class> forName(String className)

throws ClassNotFoundException {

return forName0(className, true, ClassLoader.getCallerClassLoader());

}

从上面我们可以了解不同的classloader解释的相同class也无法互相转换

这样我们把目标放在d

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值