NutzCN Logo
问答 @IocBy 关于扫描包路径问题
发布于 2862天前 作者 qq_c8b75f47 2636 次浏览 复制 上一个帖子 下一个帖子
标签:

初学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配置有关以上问题的可能

5 回复

这样

@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);
       是做什么的?

一般package命名是 域名.项目名.xxx 例如本站的 net.wendal.nutzbook.xxxx

"*加载类1", "参数1A","参数1B"....."参数1N", "*加载类2","参数2A","参数2B"....."参数2N",

区分js文件还是注解类? 不区分!!!! 星号后面是加载类名/别名, 直至下一个星号参数前,全是当前加载类的参数.

添加回复
请先登陆
回到顶部