Преглед на файлове

解决依赖分离后ClassLoader原因导致CNF的问题 fix #162

Jia_RG преди 5 години
родител
ревизия
b5e59b4ff7

+ 7 - 4
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/EnumDictHandlerRegister.java

@@ -21,7 +21,10 @@ import org.springframework.util.ClassUtils;
 
 import java.io.IOException;
 import java.lang.reflect.Array;
-import java.sql.*;
+import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.List;
 
 import static org.springframework.util.StringUtils.tokenizeToStringArray;
@@ -55,7 +58,7 @@ public class EnumDictHandlerRegister {
                 for (Resource resource : resources) {
                     try {
                         MetadataReader reader = metadataReaderFactory.getMetadataReader(resource);
-                        Class enumType = Class.forName(reader.getClassMetadata().getClassName());
+                        Class enumType = ClassUtils.forName(reader.getClassMetadata().getClassName(), null);
                         if (enumType.isEnum() && EnumDict.class.isAssignableFrom(enumType)) {
                             log.debug("register enum dict:{}", enumType);
                             DefaultDictDefineRepository.registerDefine(DefaultDictDefineRepository.parseEnumDict(enumType));
@@ -65,8 +68,8 @@ public class EnumDictHandlerRegister {
                             //注册枚举数组类型
                             typeHandlerRegistry.register(Array.newInstance(enumType, 0).getClass(), new EnumDictArrayHandler(enumType));
                         }
-                    } catch (Exception | Error ignore) {
-
+                    } catch (Exception | Error e) {
+                        log.warn("register enum dict error", e.getMessage());
                     }
                 }
             } catch (IOException e) {

+ 2 - 1
hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/MyBatisAutoConfiguration.java

@@ -38,6 +38,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Primary;
 import org.springframework.core.io.DefaultResourceLoader;
 import org.springframework.core.io.ResourceLoader;
+import org.springframework.util.ClassUtils;
 import org.springframework.util.StringUtils;
 
 import javax.sql.DataSource;
@@ -112,7 +113,7 @@ public class MyBatisAutoConfiguration {
         EnumDictHandlerRegister.register("org.hswebframework.web;" + mybatisProperties.getTypeHandlersPackage());
 
         try {
-            Class.forName("javax.persistence.Table");
+            ClassUtils.forName("javax.persistence.Table", null);
             EasyOrmSqlBuilder.getInstance().useJpa = mybatisProperties.isUseJpa();
         } catch (@SuppressWarnings("all") Exception ignore) {
         }

+ 12 - 4
hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/factory/MapperEntityFactory.java

@@ -13,21 +13,29 @@
  *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  * See the License for the specific language governing permissions and
  *  * limitations under the License.
- *  
+ *
  */
 
 package org.hswebframework.web.commons.entity.factory;
 
 import lombok.SneakyThrows;
-import org.hswebframework.web.NotFoundException;
 import org.hswebframework.utils.ClassUtils;
+import org.hswebframework.web.NotFoundException;
 import org.hswebframework.web.bean.BeanFactory;
 import org.hswebframework.web.bean.FastBeanCopier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.Modifier;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.ServiceLoader;
+import java.util.Set;
 import java.util.function.Supplier;
 
 /**
@@ -43,7 +51,7 @@ public class MapperEntityFactory implements EntityFactory, BeanFactory {
     private static final DefaultMapperFactory DEFAULT_MAPPER_FACTORY = clazz -> {
         String simpleClassName = clazz.getPackage().getName().concat(".Simple").concat(clazz.getSimpleName());
         try {
-            return defaultMapper(Class.forName(simpleClassName));
+            return defaultMapper(org.springframework.util.ClassUtils.forName(simpleClassName, null));
         } catch (ClassNotFoundException ignore) {
             // throw new NotFoundException(e.getMessage());
         }

+ 22 - 13
hsweb-core/src/main/java/org/hswebframework/web/proxy/Proxy.java

@@ -1,15 +1,24 @@
 package org.hswebframework.web.proxy;
 
-import javassist.*;
+import javassist.ClassClassPath;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.CtNewConstructor;
+import javassist.CtNewMethod;
+import javassist.LoaderClassPath;
 import javassist.bytecode.AnnotationsAttribute;
 import javassist.bytecode.ConstPool;
-import javassist.bytecode.annotation.*;
-import javassist.scopedpool.*;
+import javassist.bytecode.annotation.Annotation;
+import javassist.bytecode.annotation.ArrayMemberValue;
+import javassist.bytecode.annotation.BooleanMemberValue;
+import javassist.bytecode.annotation.ClassMemberValue;
+import javassist.bytecode.annotation.IntegerMemberValue;
+import javassist.bytecode.annotation.LongMemberValue;
+import javassist.bytecode.annotation.MemberValue;
+import javassist.bytecode.annotation.StringMemberValue;
 import lombok.Getter;
 import lombok.SneakyThrows;
-import org.springframework.core.annotation.AnnotatedElementUtils;
-import org.springframework.core.type.AnnotationMetadata;
-import org.springframework.core.type.StandardAnnotationMetadata;
 import org.springframework.util.ClassUtils;
 
 import java.util.Arrays;
@@ -24,13 +33,13 @@ import java.util.function.Consumer;
 public class Proxy<I> {
     private static final AtomicLong counter = new AtomicLong(1);
 
-    private CtClass  ctClass;
+    private final CtClass ctClass;
     @Getter
-    private Class<I> superClass;
+    private final Class<I> superClass;
     @Getter
-    private String   className;
+    private final String className;
     @Getter
-    private String   classFullName;
+    private final String classFullName;
 
     private Class<I> targetClass;
 
@@ -45,10 +54,10 @@ public class Proxy<I> {
             throw new NullPointerException("superClass can not be null");
         }
         this.superClass = superClass;
-        ClassPool classPool = new ClassPool(true);
+        ClassPool classPool = ClassPool.getDefault();
 
-        ClassPath classPath = new ClassClassPath(this.getClass());
-        classPool.insertClassPath(classPath);
+        classPool.insertClassPath(new ClassClassPath(this.getClass()));
+        classPool.insertClassPath(new LoaderClassPath(ClassUtils.getDefaultClassLoader()));
         if (classPathString != null) {
             for (String path : classPathString) {
                 classPool.insertClassPath(path);

+ 2 - 1
hsweb-datasource/hsweb-datasource-jta/src/main/java/org/hswebframework/web/datasource/jta/AtomikosDataSourceConfig.java

@@ -7,6 +7,7 @@ import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.hswebframework.web.bean.FastBeanCopier;
 import org.hswebframework.web.datasource.config.DynamicDataSourceConfig;
+import org.springframework.util.ClassUtils;
 
 import javax.sql.XADataSource;
 import java.sql.SQLException;
@@ -42,7 +43,7 @@ public class AtomikosDataSourceConfig extends DynamicDataSourceConfig {
             xaProperties.entrySet().forEach(entry -> entry.setValue(String.valueOf(entry.getValue())));
         }
         //fix #87
-        XADataSource dataSource = (XADataSource) Class.forName(getXaDataSourceClassName()).newInstance();
+        XADataSource dataSource = (XADataSource) ClassUtils.forName(getXaDataSourceClassName(), null).newInstance();
         FastBeanCopier.copy(xaProperties, dataSource);
         atomikosDataSourceBean.setXaDataSource(dataSource);
 

+ 20 - 6
hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-local/src/main/java/org/hswebframework/web/service/form/simple/SimpleDynamicFormService.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.hswebframework.expands.script.engine.DynamicScriptEngine;
+import org.hswebframework.expands.script.engine.DynamicScriptEngineFactory;
 import org.hswebframework.ezorm.core.ObjectWrapperFactory;
 import org.hswebframework.ezorm.core.Trigger;
 import org.hswebframework.ezorm.core.ValidatorFactory;
@@ -12,23 +14,34 @@ import org.hswebframework.ezorm.rdb.RDBDatabase;
 import org.hswebframework.ezorm.rdb.meta.Correlation;
 import org.hswebframework.ezorm.rdb.meta.RDBColumnMetaData;
 import org.hswebframework.ezorm.rdb.meta.RDBTableMetaData;
-import org.hswebframework.ezorm.rdb.meta.converter.*;
+import org.hswebframework.ezorm.rdb.meta.converter.BlobValueConverter;
+import org.hswebframework.ezorm.rdb.meta.converter.ClobValueConverter;
+import org.hswebframework.ezorm.rdb.meta.converter.DateTimeConverter;
+import org.hswebframework.ezorm.rdb.meta.converter.DefaultValueConverter;
+import org.hswebframework.ezorm.rdb.meta.converter.JSONValueConverter;
+import org.hswebframework.ezorm.rdb.meta.converter.NumberValueConverter;
 import org.hswebframework.ezorm.rdb.render.dialect.Dialect;
 import org.hswebframework.ezorm.rdb.simple.trigger.ScriptTraggerSupport;
-import org.hswebframework.expands.script.engine.DynamicScriptEngine;
-import org.hswebframework.expands.script.engine.DynamicScriptEngineFactory;
 import org.hswebframework.web.BusinessException;
 import org.hswebframework.web.commons.entity.DataStatus;
 import org.hswebframework.web.dao.form.DynamicFormColumnDao;
 import org.hswebframework.web.dao.form.DynamicFormDao;
 import org.hswebframework.web.dict.EnumDict;
-import org.hswebframework.web.entity.form.*;
+import org.hswebframework.web.entity.form.DictConfig;
+import org.hswebframework.web.entity.form.DynamicFormColumnBindEntity;
+import org.hswebframework.web.entity.form.DynamicFormColumnEntity;
+import org.hswebframework.web.entity.form.DynamicFormDeployLogEntity;
+import org.hswebframework.web.entity.form.DynamicFormEntity;
 import org.hswebframework.web.id.IDGenerator;
 import org.hswebframework.web.service.DefaultDSLDeleteService;
 import org.hswebframework.web.service.DefaultDSLQueryService;
 import org.hswebframework.web.service.DefaultDSLUpdateService;
 import org.hswebframework.web.service.GenericEntityService;
-import org.hswebframework.web.service.form.*;
+import org.hswebframework.web.service.form.DatabaseRepository;
+import org.hswebframework.web.service.form.DynamicFormDeployLogService;
+import org.hswebframework.web.service.form.DynamicFormService;
+import org.hswebframework.web.service.form.FormDeployService;
+import org.hswebframework.web.service.form.OptionalConvertBuilder;
 import org.hswebframework.web.service.form.events.FormDeployEvent;
 import org.hswebframework.web.service.form.initialize.ColumnInitializeContext;
 import org.hswebframework.web.service.form.initialize.DynamicFormInitializeCustomizer;
@@ -46,6 +59,7 @@ import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ClassUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
@@ -747,7 +761,7 @@ public class SimpleDynamicFormService extends GenericEntityService<DynamicFormEn
         Class clazz = classMapping.get(type);
         if (clazz == null) {
             try {
-                clazz = Class.forName(type);
+                clazz = ClassUtils.forName(type, null);
             } catch (ClassNotFoundException e) {
                 throw new RuntimeException(e);
             }

+ 7 - 3
hsweb-system/hsweb-system-dynamic-form/hsweb-system-dynamic-form-local/src/main/java/org/hswebframework/web/service/form/simple/validator/jsr303/AbstractStrategy.java

@@ -10,13 +10,17 @@ import org.hswebframework.web.service.form.simple.validator.JSR303AnnotationInfo
 import org.hswebframework.web.service.form.simple.validator.JSR303AnnotationParserStrategy;
 import org.hswebframework.web.validator.group.CreateGroup;
 import org.hswebframework.web.validator.group.UpdateGroup;
+import org.springframework.util.ClassUtils;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import java.lang.annotation.Annotation;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.function.Function;
-import java.util.stream.Collectors;
 
 /**
  * @author zhouhao
@@ -104,7 +108,7 @@ public abstract class AbstractStrategy implements JSR303AnnotationParserStrategy
                     return UpdateGroup.class;
                 } else {
                     try {
-                        return Class.forName(String.valueOf(obj));
+                        return ClassUtils.forName(String.valueOf(obj), null);
                     } catch (ClassNotFoundException e) {
                         return CreateGroup.class;
                     }