Пример #1
0
  /** 解析SourceFloder下搜索到的文件名以config.xml结尾的文件,将其中配置的Bean返回 */
  public List<Bean> getBeans() {
    List<String> fileList = Files.list(Files.root(), "^.*config.xml$", true); // 搜索以config.xml结尾的文件
    log.info("Found " + fileList.size() + " Xml config files at " + Files.root());

    List<Bean> beans = new ArrayList<Bean>();
    for (String filePath : fileList) {
      NodeList beanNodes =
          (NodeList) Files.xpath(Files.build(filePath), "//bean", XPathConstants.NODESET);
      for (int length = (null == beanNodes ? -1 : beanNodes.getLength()), i = 0; i < length; i++) {
        Bean iocBean = new Bean(); // 一个新的Bean
        iocBean.name = Files.xpath(beanNodes.item(i), "@name", XPathConstants.STRING).toString();
        String type = Files.xpath(beanNodes.item(i), "@class", XPathConstants.STRING).toString();
        try {
          iocBean.type = Class.forName(type);
        } catch (ClassNotFoundException e) { // 配置文件中把类名写错了
          throw new RuntimeException(
              "Class " + type + " not found , which is configured in " + filePath, e);
        }
        NodeList propertyNodes =
            (NodeList) Files.xpath(beanNodes.item(i), "property", XPathConstants.NODESET);
        for (int len = (null == propertyNodes ? -1 : propertyNodes.getLength()), m = 0;
            m < len;
            m++) {
          Field field = new Field(); // 一个新的Field
          field.name = (String) Files.xpath(propertyNodes.item(m), "@name", XPathConstants.STRING);
          field.type = Reflect.fieldType(iocBean.type, field.name);
          field.value =
              (String) Files.xpath(propertyNodes.item(m), "@value", XPathConstants.STRING);
          iocBean.fields.add(field);
        }
        beans.add(iocBean);

        log.debug("ADD BEAN: Xml " + iocBean.type.getName() + " " + iocBean.name);
      }
    }
    return beans;
  }
Пример #2
0
 public void test() {
   ThreadUtil.sleep(123);
   log.debug("目标方法正在执行");
 }
Пример #3
0
 @Trans
 @Aop(_LogFilter.class)
 public String sayHi(String msg1, String msg2) {
   log.debug("user say hi");
   return msg1 + "\t" + msg2;
 }