Package test

Source Code of test.EWebConfigInit

package test;

import org.eweb4j.config.ConfigBeanCreator;
import org.eweb4j.config.ConfigConstant;
import org.eweb4j.config.EWeb4JConfig;
import org.eweb4j.config.bean.ConfigBean;
import org.eweb4j.config.bean.Prop;

public class EWebConfigInit {

  public static void main(String[] args) {

    ConfigBean cb = ConfigBeanCreator.getConfigBean();

    // 设置是否每次启动框架都重新读取配置文件
    cb.setReload("false");

    // --------设置properties配置文件----------------------------
    Prop prop = new Prop();
    // 是否全局
    prop.setGlobal("false");
    // 文件ID
    prop.setId("DemoConstant");
    // 文件保存路径,相对路径,相对于${ConfigBasePath}
    prop.setPath("demo-constant.properties");
    cb.getProperties().getFile().add(prop);
    // -----------------------------------------------------------

    // --------IOC相关的配置---------------------------------------
    cb.getIoc().setOpen("true");
    // 是否开启调试功能,目前调试仅是控制台输出日志信息
    cb.getIoc().setDebug("true");
    // 日志文件保存路径,相对于${ConfigBasePath}
    cb.getIoc().setLogFile("ioc.log");
    // 日志文件最大大小,单位MB
    cb.getIoc().setLogMaxSize("5");
    // 添加一个hello-ioc.xml
    cb.getIoc().getIocXmlFiles().getPath().add("hello-ioc.xml");
    // ------------------------------------------------------------

    // -----------ORM相关的配置-------------------------------------
    // ORM开关,开启了之后,框架在启动的时候会尝试去连接数据库
    cb.getOrm().setOpen("true");
    cb.getOrm().setDebug("true");
    cb.getOrm().setLogFile("orm.log");
    cb.getOrm().setLogMaxSize("5");
    // 设置数据源
    cb.getOrm().setDataSource("com.mchange.v2.c3p0.ComboPooledDataSource");
    // 设置扫描的包名,框架会扫描该包及其子包中所有的类,发现实体类后会加载配置信息,可以填写 "." 表示当前类路径
    cb.getOrm().getScanPojoPackage().getPath().add("org.eweb4j");
    // 设置数据库连接信息配置的文件
    cb.getOrm().getDbInfoXmlFiles().getPath().add("mysql.xml");
    // ------------------------------------------------------

    // ----------MVC相关的配置--------------------------------
    // MVC开关,开启之后,要在WEB-INF/web.xml中配置EWebFilter或EWebServlet才能使用MVC的所有功能
    cb.getMvc().setOpen("true");
    cb.getMvc().setDebug("true");
    cb.getMvc().setLogFile("mvc.log");
    cb.getMvc().setLogMaxSize("5");
    // 设置Action的配置文件,跟Struts类似
    cb.getMvc().getScanActionPackage().getPath()
        .add("hello-world-action.xml");
    // 设置Action的拦截器配置文件
    cb.getMvc().getInterXmlFiles().getPath().add("interceptor.xml");
    // ------------------------------------------------------

    // 默认的start.xml文件名:eweb4j-start-config.xml
    String path = ConfigConstant.START_FILE_PATH();
    // 生成 start.xml
    try {
      EWeb4JConfig.createStartXml(path, cb);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // 启动框架,让框架自动生成设置好的hello-ioc.xml
    EWeb4JConfig.start();
  }

}
TOP

Related Classes of test.EWebConfigInit

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.