最近看代码,进入依赖的包的class文件,每个方法只有RuntimeException,如下(mock的):
public class MyServiceContainer {
public static final AppServiceContainer SHARED_CONTAINER;
public MyServiceContainer() {
throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx.");
}
public static AppServiceContainer createAppServiceContainer(ApplicationModel var0) {
throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx.");
}
public static <T> T getInstance(Class<T> var0) {
throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx.");
}
public static <T> List<T> getInstances(Class<T> var0, String... var1) {
throw new RuntimeException("com.loserwang.MyServiceContainer was loaded by " + MyServiceContainer.class.getClassLoader() + ", it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxxxx."");
}
然后下载source文件:
public class MyServiceContainer {
public static final AppServiceContainer SHARED_CONTAINER;
public MyServiceContainer() {
super();
}
public static AppServiceContainer createAppServiceContainer(ApplicationModel var0) {
// 具体逻辑代码
}
public static <T> T getInstance(Class<T> var0) {
// 具体逻辑代码
}
public static <T> List<T> getInstances(Class<T> var0, String... var1) {
// 具体逻辑代码
}
既然class文件是通过java文件编译的,为什么会有如此大的区别呢?
补充:
淦,我搞明白了。maven下载jar包中的class文件并不是由源代码编译而成,而是一个fake sdk class,写代码和编译时不会报错。但是运行时就会报错。
必须使用公司的容器来加载。该容器中有自定义的类加载器,不会加载该fake class,而是会加载内置的class(由源代码编译而成)。
有点类似接口或者spi了。