- 🔭 I’m Java engineer
- 🌱 I’m working in hangzhou
- 👯 I’m like openSource
- 😄 Pronouns: 莫那鲁道
Java extension plugin and hot swap plugin(Java 扩展点/插件系统,支持热插拔,旨在解决大部分软件的功能定制问题)
License: Apache License 2.0
如题,例如test_simplecodeController类里面有个这样的服务类,然后是通过服务类test_simplecodeService调用业务逻辑的,
@Autowired
private Test_simplecodeService test_simplecodeService;
目前插件加载后直接调用Controller类好像没有办法直接实例化接口,提示 Error creating bean with name 'kpaas.third.plugin.Test_simplecodeController___kpaas_1.0.0': Unsatisfied dependency expressed through field 'test_simplecodeService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Test_simplecodeService': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [kpaas.service.Test_simplecodeService]: Specified class is an interface
如果使用了插件,这里要对test_simplecodeService做什么改造 才能被test_simplecodeController类使用呢?
建议在cn.think.in.java.open.exp.adapter.springboot2.SpringBootObjectStore类中加上,卸载插件的时候,顺便将对应的bean移除。
/**
* bean移除
* @param beanName
*/
public void unregisterBean(String beanName){
log.info("unregisterBean->beanName:{}",beanName);
beanDefinitionRegistry.removeBeanDefinition(beanName);
}
private void unRegisterCallback(Class<?> aClass, String pluginId) {
String name = UniqueNameUtil.getName(aClass, pluginId);
RestUrlScanComponent urlComponent = cache.get(name);
if (urlComponent != null) {
unregisterBean(name);
urlComponent.unRegister();
cache.remove(name);
}
}
如果把这个热加载插件做成一个开放能力,插件由其他开发者提供,有没有安全机制可以控制插件代码的执行范围,类似沙箱机制,就算里面有恶意代码也不会影响操作系统和主程序运行,比如只能操作指定的操作目录,禁止高危函数等。
不太明白各模块的作用,比如example-springboot2,它是主应用吗?如果是的话,拓展接口不应该在这个模块里面吗,同时example-plugin-a-v1插件又是怎么被使用的呢?
请问兄弟,如果服务是集群部署,这个场景怎么解?
expAppContext = Bootstrap.bootstrap("/Users/liushao/Downloads/exp-main/exp-plugins/","/Users/liushao/Downloads/exp-main/example/simple-java-app/");
启动后报错如下:
14:48:36.491 [main] INFO cn.think.in.java.open.exp.core.impl.Bootstrap - 准备安装插件, 压缩包路径: /Users/liushao/Downloads/exp-main/exp-plugins/example-plugin-b-v2-1.0-SNAPSHOT-1.0-SNAPSHOT.zip
14:48:36.540 [main] INFO cn.think.in.java.open.exp.classloader.support.ClassLoaderFinder - dir /Users/liushao/Downloads/exp-main/example/simple-java-app//cn.think.in.java.open.exp.example.b_2.0.0 isParentMode = parent-first
14:49:04.279 [main] ERROR cn.think.in.java.open.exp.core.impl.Bootstrap - java.lang.NoClassDefFoundError: Lorg/mybatis/spring/SqlSessionTemplate; ---->>>> /Users/liushao/Downloads/exp-main/exp-plugins/example-plugin-b-v2-1.0-SNAPSHOT-1.0-SNAPSHOT.zip
java.lang.RuntimeException: java.lang.NoClassDefFoundError: Lorg/mybatis/spring/SqlSessionTemplate;
hello, I find in the class open.exp.adapter.springboot.common.starter there has logic as below:
`
public static boolean needEnhancer(Object o) {
return !(o instanceof ExPIntercept);
}
public static Object getEnhancer(Object b, String pluginId) {
if (!needEnhancer(b)) {
return b;
}
Enhancer enhancer = new Enhancer();
enhancer.setInterfaces(new Class[]{ExPIntercept.class});
enhancer.setSuperclass(b.getClass());
enhancer.setNamingPolicy(new DefaultNamingPolicy() {
@Override
protected String getTag() {
return super.getTag() + "$$MDC$$" + pluginId;
}
});
enhancer.setCallback(new MDCExpMethodInterceptor(pluginId, b));
return enhancer.create();
}
`
as the getEnhancer method, if the b instanceof ExPIntercept return false, the Enhancer enhancer = new Enhancer(); could reach, but it set the ExPIntercept as it's Interface, so I think if reach this code, the param b is instanceof ExPIntercept.
if I am right, If it is right, I will submit pr to fix this.
您好,想问一下,如果想获取主应用的某个对象,有办法获取吗?
插件集成mybatis后,mapper层的类无法注入到spring
非前后端分类项目:jsp/thymeleaf 是否支持呀?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.