Nutz ioc 如何注入数组或可变参数
工厂方法
public static Server createTcpServer(String... args) throws SQLException {
TcpServer service = new TcpServer();
Server server = new Server(service, args);
service.setShutdownHandler(server);
return server;
}
ioc配置
h2Server : {
type : "org.h2.tools.Server",
args : [
[ "-tcp", "-tcpAllowOthers", "-tcpPort", "8082" ]
],
factory : "org.h2.tools.Server#createTcpServer",
events : {
create : "start",
depose : "stop"
}
}
异常
Exception in thread "main" org.nutz.ioc.IocException: [h2Server] # FAIL to create Ioc Bean name=[h2Server]
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:149)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at org.gx.shiro.Main.main(Main.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.NoSuchMethodException: Fail to find Method org.h2.tools.Server->createTcpServer with params:
["java.util.ArrayList"]
at org.nutz.lang.Mirror.findMethod(Mirror.java:1142)
at org.nutz.lang.Mirror.findMethod(Mirror.java:1118)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:101)
... 8 more