mirror of
https://gitee.com/nutz/nutzboot.git
synced 2024-11-30 02:38:28 +08:00
fix: II92L@gitee urule集成后, @ActionBean没注册到urule内
This commit is contained in:
parent
582efbd1f8
commit
68c9bb4c76
@ -1,5 +1,6 @@
|
||||
package org.nutz.boot.starter.urule;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -10,13 +11,21 @@ import org.nutz.ioc.impl.PropertiesProxy;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Files;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
import com.bstek.urule.Utils;
|
||||
import com.bstek.urule.model.function.FunctionDescriptor;
|
||||
import com.bstek.urule.model.library.action.SpringBean;
|
||||
import com.bstek.urule.model.library.action.annotation.ActionBean;
|
||||
import com.bstek.urule.runtime.BuiltInActionLibraryBuilder;
|
||||
|
||||
@IocBean(create="init")
|
||||
public class UruleSpringEnvStarter extends SpringWebContextProxy {
|
||||
|
||||
private static final Log log = Logs.get();
|
||||
|
||||
@Inject
|
||||
protected PropertiesProxy conf;
|
||||
|
||||
@ -39,6 +48,7 @@ public class UruleSpringEnvStarter extends SpringWebContextProxy {
|
||||
return names;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
super.contextInitialized(sce);
|
||||
Map<String, FunctionDescriptor> functionDescriptorMap = Utils.getFunctionDescriptorMap();
|
||||
@ -51,5 +61,33 @@ public class UruleSpringEnvStarter extends SpringWebContextProxy {
|
||||
functionDescriptorLabelMap.put(fun.getLabel(), fun);
|
||||
}
|
||||
// TODO 待urule调整Utils中DebugWriter的写法后,兼容DebugWriter的注入
|
||||
|
||||
// 注入ActionBean试试
|
||||
try {
|
||||
String[] names = appContext.getIoc().getNamesByAnnotation(ActionBean.class);
|
||||
BuiltInActionLibraryBuilder builder = applicationContext.getBean(BuiltInActionLibraryBuilder.class);
|
||||
Method method = BuiltInActionLibraryBuilder.class.getDeclaredMethod("buildMethod", Method[].class);
|
||||
method.setAccessible(true);
|
||||
for (String name : names) {
|
||||
if (Strings.isBlank(name))
|
||||
continue;
|
||||
Object obj = appContext.getIoc().get(null, name);
|
||||
Class<?> klass = obj.getClass();
|
||||
ActionBean ab = klass.getAnnotation(ActionBean.class);
|
||||
if (ab == null) {
|
||||
klass = klass.getSuperclass();
|
||||
ab = klass.getAnnotation(ActionBean.class);
|
||||
}
|
||||
log.debug("add ActionBean : " + klass.getName());
|
||||
SpringBean bean = new SpringBean();
|
||||
bean.setId(name);
|
||||
bean.setName(ab.name());
|
||||
bean.setMethods((List<com.bstek.urule.model.library.action.Method>) method.invoke(builder, new Object[] {klass.getMethods()}));
|
||||
builder.getBuiltInActions().add(bean);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package io.nutz.demo.simple.action;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import com.bstek.urule.model.library.action.annotation.ActionBean;
|
||||
import com.bstek.urule.model.library.action.annotation.ActionMethod;
|
||||
import com.bstek.urule.model.library.action.annotation.ActionMethodParameter;
|
||||
|
||||
@IocBean
|
||||
@ActionBean(name="NB字符串")
|
||||
public class UruleCustomAction {
|
||||
|
||||
@ActionMethod(name="去空格")
|
||||
@ActionMethodParameter(names={"目标字符串"})
|
||||
public String trim(String str){
|
||||
if(str==null){
|
||||
return str;
|
||||
}
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
@ActionMethod(name="指定起始的字符串截取")
|
||||
@ActionMethodParameter(names={"目标字符串","开始位置","结束位置"})
|
||||
public String substring(String str,int start,int end){
|
||||
return str.substring(start, end);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user