解决启动 V5.5 后端项目二开代码分离控制问题
报错:解决首次启动 V5.5 后端项目报 "不符合项目二开代码分离控制规范,存在文件"
1. 在 com.epichust 文件夹里创建 MyClassLoader.java,复制下面代码:
package com.epichust;
import com.epichust.mestar.logging.Slf4jLogDelegator;
import com.epichust.mestar.utils.path.EnvUtil;
import com.google.common.base.Joiner;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
public class MyClassLoader extends URLClassLoader {
private static final Set<String> names = new HashSet();
private static final Slf4jLogDelegator slf4jLogDelegator = new Slf4jLogDelegator();
private static MyClassLoader mc;
private Set<String> codeControlConfig = new HashSet<>();
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (name.startsWith("com.epichust") && !names.contains(name)) {
try {
Enumeration<URL> resources = this.getResources(name.replaceAll("\\.", "/") + ".class");
ArrayList urls = new ArrayList();
while(resources.hasMoreElements()) {
urls.add(resources.nextElement());
}
if (urls.size() > 1) {
codeControlConfig.add(name);
slf4jLogDelegator.error("在\"application.xml\"文件中[code.control]配置行追加如下参数:" + Joiner.on(",").join(codeControlConfig));
} else {
names.add(name);
}
} catch (IOException var4) {
slf4jLogDelegator.error(var4.getMessage());
}
}
return super.loadClass(name);
}
public static MyClassLoader getMc(ClassLoader parent) {
if (mc == null) {
String libPath = EnvUtil.getContextLibPath();
URL[] urls = Path2URL(new File(libPath));
mc = new MyClassLoader(urls, parent);
}
return mc;
}
public void setMc(MyClassLoader mc) {
MyClassLoader.mc = mc;
}
private MyClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
super(urls, parent, factory);
}
private MyClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
}
private MyClassLoader(URL[] urls) {
super(urls);
}
public void addURL(URL... urls) {
URL[] var2 = urls;
int var3 = urls.length;
for(int var4 = 0; var4 < var3; ++var4) {
URL url = var2[var4];
System.out.println("加载类路径:" + url.toString());
super.addURL(url);
}
}
public void addJar(File... files) {
if (files != null && files.length != 0) {
File[] var2 = files;
int var3 = files.length;
for(int var4 = 0; var4 < var3; ++var4) {
File file = var2[var4];
try {
this.addURL(file.toURI().toURL());
} catch (MalformedURLException var7) {
var7.printStackTrace();
}
}
}
}
public void addClassPath(String classPath) {
if (!this.isEmpty(classPath)) {
this.addClassPath(new File(classPath));
}
}
public void addClassPath(File path) {
if (!path.isFile()) {
try {
this.addURL(path.toURI().toURL());
} catch (MalformedURLException var3) {
var3.printStackTrace();
}
}
}
public void addJarPath(File path) {
URL[] urls = Path2URL(path);
if (urls != null && urls.length != 0) {
this.addURL(urls);
}
}
public static URL[] Path2URL(File path) {
if (path.isFile()) {
return new URL[0];
} else {
File[] files = path.listFiles();
if (files == null) {
return new URL[0];
} else {
URL[] urls = new URL[files.length];
for(int i = 0; i < files.length; ++i) {
try {
urls[i] = files[i].toURI().toURL();
} catch (MalformedURLException var5) {
var5.printStackTrace();
}
}
return urls;
}
}
}
@Override
public InputStream getResourceAsStream(String name) {
return super.getResourceAsStream(name);
}
@Override
public URL findResource(String name) {
return super.findResource(name);
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
return super.getResources(name);
}
private boolean isEmpty(String classPath) {
return classPath == null || classPath.trim().length() <= 0;
}
static {
String property = EnvUtil.getMestarHomeApplicationProperties().getProperty("code.control");
if (property != null) {
String[] split = property.split(",");
names.addAll(Arrays.asList(split));
}
names.addAll(Arrays.asList("com.epichust.annotation.InterfaceLog,com.epichust.mestar.msg.manager.MsgCommonService,com.epichust.mestar.sys.account.service.SysMestarAuthenticationManager,com.epichust.mestar.rule.RuleUtil,com.epichust.message.camel.MestarCamelService,com.epichust.expense.service.MyAuthenticationProvider,com.epichust.service.interfaces.UnimaxInterfaceResendServies,com.epichust.mestar.msg.service.MsgReceiveService,com.epichust.mestar.msg.entity.MsgTemplate,com.epichust.ws.service.BaseDataSelectService,com.epichust.mestar.msg.web.MsgDetailController,com.epichust.facade.unimax.IRedisProxy,com.epichust.mestar.msg.controller.MsgTemplateController,com.epichust.mestar.sys.account.service.SysRoleService,com.epichust.mestar.dao.MbrRuleTriggerFilterDao,com.epichust.mestar.operation.controller.impl.AbsProcessor,com.epichust.entity.MbbInterfaceDetail,com.epichust.mestar.rule.entity.MbrRuleTrigger,com.epichust.mestar.log.web.LogAction,com.epichust.mestar.msg.entity.MsgTiming,com.epichust.service.unimax.ShardedRedisProxyService,com.epichust.mestar.rule.entity.MbrEntity,com.epichust.util.unimax.EnumBase$EMaterialType,com.epichust.entity.MbbQualificationOparetion,com.epichust.entity.MbbQualificationEmployee,com.epichust.mestar.domain.interceptor.AuditTrailInterceptor,com.epichust.mestar.activiti.web.ActTaskController,com.epichust.mestar.msg.entity.MsgReceive,com.epichust.mestar.msg.web.MsgReceiveController,com.epichust.mestar.domain.BaseEntity,com.epichust.mestar.mail.manager.MestarMailService,com.epichust.util.unimax.EnumBase$EWorkCellAttrFlag,com.epichust.mestar.activiti.manager.ActModelManager,com.epichust.util.unimax.EnumBase$EModuleName,com.epichust.mestar.msg.repository.MsgTemplateDao,com.epichust.mestar.rule.service.MbrRuleTriggerService,com.epichust.mestar.bo.MbrRuleTriggerFilterBo,com.epichust.mestar.rule.service.MestarRuleEngine,com.epichust.entity.MbbQulificationClass,com.epichust.mestar.rule.web.MbrEntityController,com.epichust.mestar.management.controller.AutoLoginController,com.epichust.entity.MbbQulification,com.epichust.mestar.log.service.impl.UserLogServiceImpl,com.epichust.mestar.msg.service.MsgDetailService,com.epichust.aop.unimax.InterfaceLogAspect,com.epichust.mestar.activiti.manager.ActTaskManager,com.epichust.mestar.domain.event.MestarPostInsertEventListener,com.epichust.dao.unimax.UempEquipPlanDao,com.epichust.util.unimax.EnumBase$EWorkCenterClassFlag,com.epichust.service.unimax.RedisProxyService,com.epichust.mestar.msg.manager.MsgSendService,com.epichust.mestar.msg.manager.IMsgSendService,com.epichust.mestar.domain.event.MestarPostUpdateEventListener,com.epichust.entity.MbbQualificationWC,com.epichust.util.unimax.EnumBase$EFactoryTree,com.epichust.mestar.msg.manager.MsgTemplateManager,com.epichust.mestar.mes.common.dao.MesCommonDao".split(",")));
mc = null;
try {
ClassLoader.registerAsParallelCapable();
} catch (Throwable var2) {
}
}
}
2. 重新启动项目,查看 Mes.log 日志,并搜索 "code.control", 找到最后一行日志
3. 在 "application.xml" 文件中 [code.control] 配置行追加如下参数:
在"application.xml"文件中[code.control]配置行追加如下参数:com.epichust.entity.PmbfWorkCell,com.epichust.entity.UqcmBdCitem,com.epichust.entity.UmppWorkOrder,com.epichust.entity.in.WmsInTask