初学nutz,有个关于包路径扫描问题,如何配置同级和多级目录
@IocBy(type=ComboIocProvider.class, args={"*js", "com/config/ioc/", "*anno", "com.module", "*tx", "*org.nutz.integration.quartz.QuartzIocLoader"})
我将所有配置@IocBean的类放入com.module,可正常扫描到;
若是将一个类,放在com.service.impl中,如何配置才可将此包扫描到呢??
1、尝试了@IocBy(type=ComboIocProvider.class, args={"*js", "com/config/ioc/", "*anno", "com.module,com.service.impl", "*tx", "*org.nutz.integration.quartz.QuartzIocLoader"}),所有配置@IocBean的类均无法扫描到,提示WARN - Moudle with @InjectName('xxxx') or @IocBean('xxxx') but no such ioc bean found!! Pls check your ioc configure!!.....
2、尝试了@IocBy(type=ComboIocProvider.class, args={"*js", "com/config/ioc/", "*anno", "com.*", "*tx", "*org.nutz.integration.quartz.QuartzIocLoader"}),运行提示结果同上
同时查找了下 IocProvider 源码 没有args配置有关以上问题的可能
这样
@IocBy(type=ComboIocProvider.class, args={"*js", "com/config/ioc/",
"*anno", "com.module", "com.service.impl",
"*tx",
"*org.nutz.integration.quartz.QuartzIocLoader"})
另外, 哪有人这样命名的,尽早改成 com.yourname.module, com.yourname.service.impl 才是正路
嘿嘿 刚想问的是若是再来个其他包的路径比如 com.zllh.job,配置应该是 @IocBy(type=ComboIocProvider.class, args={"*js", "com/zllh/config/ioc/", "*anno", "com.zllh.module", "com.zllh.service.impl","com.zllh.job", "*tx", "*org.nutz.integration.quartz.QuartzIocLoader"})吧
刚刚看到 ComboIocProvider中ComboIocLoader的构造方法,
public ComboIocLoader(String... args) throws ClassNotFoundException {
if (loaders.isEmpty()) {
loaders.put("js", JsonLoader.class);
loaders.put("json", JsonLoader.class);
loaders.put("xml", XmlIocLoader.class);
loaders.put("annotation", AnnotationIocLoader.class);
loaders.put("anno", AnnotationIocLoader.class);
loaders.put("trans", TransIocLoader.class);
loaders.put("tx", TransIocLoader.class);
loaders.put("props", PropertiesIocLoader.class);
loaders.put("properties", PropertiesIocLoader.class);
loaders.put("async", AsyncAopIocLoader.class);
try {
loaders.put("cache",
(Class<? extends IocLoader>) Lang.loadClass("org.nutz.jcache.NutCacheIocLoader"));
}
catch (ClassNotFoundException e) {}
try {
loaders.put("quartz",
(Class<? extends IocLoader>) Lang.loadClass("org.nutz.integration.quartz.QuartzIocLoader"));
}
catch (ClassNotFoundException e) {}
}
ArrayList argsList = null;
String currentClassName = null;
for (String str : args) {
if (str.length() > 0 && str.charAt(0) == '*') {
if (argsList != null)
createIocLoader(currentClassName, argsList);
currentClassName = str.substring(1);
argsList = new ArrayList();
} else {
if (argsList == null) {
throw new IllegalArgumentException("ioc args without Loader ClassName. "
+ Arrays.toString(args));
}
argsList.add(str);
}
}
if (currentClassName != null)
createIocLoader(currentClassName, argsList);
Set<String> beanNames = new HashSet<String>();
for (IocLoader loader : iocLoaders) {
for (String beanName : loader.getName()) {
if (!beanNames.add(beanName) && log.isWarnEnabled())
log.warnf("Found Duplicate beanName=%s, pls check you config! loader=%s", beanName,loader.getClass());
}
}
}
看的似懂非懂的
除了,str以*开头的,其他都是需要扫描的,如何区分扫描出来的 是js文件还是注解类呢?
loaders.put("js", JsonLoader.class);
loaders.put("json", JsonLoader.class);
loaders.put("xml", XmlIocLoader.class);
loaders.put("annotation", AnnotationIocLoader.class);
loaders.put("anno", AnnotationIocLoader.class);
loaders.put("trans", TransIocLoader.class);
loaders.put("tx", TransIocLoader.class);
loaders.put("props", PropertiesIocLoader.class);
loaders.put("properties", PropertiesIocLoader.class);
loaders.put("async", AsyncAopIocLoader.class);
是做什么的?