---
title: "Spring的ClassLoader.getDefaultClassLoader()"
author: "zwxiaole"
date: "2015-05-11T14:06:27Z"
tags: []
categories: ["企业架构"]
slug: "spring-classloader-getdefaultclassloader"
draft: false
lastmod: "2015-05-11T14:07:20Z"
id: 2210158
url: "https://zwxiaole.iteye.com/blog/2210158"
---

```
public static ClassLoader getDefaultClassLoader() {
		ClassLoader cl = null;
		try {
			cl = Thread.currentThread().getContextClassLoader();
		}
		catch (Throwable ex) {
			// Cannot access thread context ClassLoader - falling back...
		}
		if (cl == null) {
			// No thread context class loader -> use class loader of this class.
			cl = ClassUtils.class.getClassLoader();
			if (cl == null) {
				// getClassLoader() returning null indicates the bootstrap ClassLoader
				try {
					cl = ClassLoader.getSystemClassLoader();
				}
				catch (Throwable ex) {
					// Cannot access system ClassLoader - oh well, maybe the caller can live with null...
				}
			}
		}
		return cl;
	}
```

 首先  是取 当前线程的 classloader

取不到 去取当前类的 classloader

还是取不到 就取java默认的系统的classloader