Package net.hasor.core

Examples of net.hasor.core.AppContext


public class StartTest {
    @Test
    public void startTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>startTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext();
        //
        StartTest a = appContext.getInstance(StartTest.class);
        System.out.println(a);
       
        String userHome = appContext.getEnvironment().getEnvVar("user.home");
      System.out.println( new File(userHome,"aaa/aaa.txt").getParentFile().mkdirs()   );
    }
View Full Code Here


public class NameBindTest {
    @Test
    public void nameBindTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>nameBindTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                //绑定一个接口和实现类
                apiBinder.bindType(CharSequence.class).nameWith("ModuleA").toInstance("this String form A");
                apiBinder.bindType(CharSequence.class).nameWith("ModuleB").toInstance("this String form B");
            }
        });
        //
        System.out.println();
        CharSequence modeSay = null;
        modeSay = appContext.findBindingBean("ModuleA", CharSequence.class);
        Hasor.logInfo(modeSay.toString());
        modeSay = appContext.findBindingBean("ModuleB", CharSequence.class);
        Hasor.logInfo(modeSay.toString());
        //
        List<CharSequence> says = appContext.findBindingBean(CharSequence.class);//查找绑定
        Hasor.logInfo("say %s.", says);
    }
View Full Code Here

*/
public class EventLinkTest {
    @Test
    public void syncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>syncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        final String EventName = "MyEvent";//事件链的终端
        final String SeedEvent = "SeedEvent";//种子事件
        //1.添加事件监听器F
        ec.addListener(EventName, new MyListener());
        ec.addListener(SeedEvent, new EventListener() {
            public void onEvent(String event, Object[] params) throws Throwable {
                AppContext app = (AppContext) params[0];
                EventContext localEC = app.getEnvironment().getEventContext();
                System.out.println("before MyEvent.");
                localEC.fireAsyncEvent(EventName, 1);
                localEC.fireAsyncEvent(EventName, 2);
            }
        });
View Full Code Here

public class SimpleParam_QueryTest {
    @Test
    public void simpleParam_QueryTest() throws IOException, URISyntaxException, InterruptedException, SQLException {
        System.out.println("--->>simpleParam_QueryTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        List<Map<String, Object>> userList = jdbc.queryForList("select * from TB_User where userUUID like ?", "76%");
        HasorUnit.printMapList(userList);
    }
View Full Code Here

public class Callable_Test {
    @Test
    public void testCallable() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>testCallable<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        //
        //        int flowID = jdbc.execute(new ConnectionCallback<Integer>() {
        //            public Integer doInConnection(Connection con) throws SQLException, DataAccessException {
        //                String callSQL = "exec PR_BuildFlowTID ?,?";
View Full Code Here

*/
public class ModuleTest {
    @Test
    public void moduleTest() throws IOException, URISyntaxException {
        System.out.println("--->>moduleTest<<--");
        AppContext appContext = Hasor.createAppContext(new Mod_1(), new Mod_2(), new Mod_3());
        //
        List<String> says = appContext.findBindingBean(String.class);
        Hasor.logInfo("all modules say:%s.", says);
    }
View Full Code Here

public class NameBindTest {
    @Test
    public void nameBindTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>nameBindTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                //Bean1
                apiBinder.bindType(PojoBean.class).idWith("myBean1");
                //Bean2
                PojoBean pojo = new PojoBean();
                pojo.setName("马大帅");
                apiBinder.bindType(PojoBean.class).idWith("myBean2").toInstance(pojo);
            }
        });
        //
        PojoBean myBean1 = appContext.getInstance("myBean1");
        System.out.println(myBean1.getName() + "\t" + myBean1);
        PojoBean myBean2 = appContext.getInstance("myBean2");
        System.out.println(myBean2.getName() + "\t" + myBean2);
    }
View Full Code Here

*/
public class EnvironmentVariablesTest {
    @Test
    public void environmentVariablesTest() throws Exception {
        System.out.println("--->>environmentVariablesTest<<--");
        AppContext appContext = Hasor.createAppContext();
        Environment env = appContext.getEnvironment();
        //
        //JAVA_HOME
        System.out.println(env.getEnvVar("JAVA_HOME"));
        //HASOR_WORK_HOME,该环境变量由 hasor 的配置文件提供,仅在Hasor框架内有效
        System.out.println(env.getEnvVar("HASOR_WORK_HOME"));
View Full Code Here

*/
public class AsyncEventTest {
    @Test
    public void asyncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>asyncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        String EventName = "MyEvent";
        //1.添加事件监听器
        ec.addListener(EventName, new MyListener());
        //2.引发异步事件
View Full Code Here

*/
public class SimpleSettingsTest {
    @Test
    public void simpleSettingsTest() throws IOException, URISyntaxException {
        System.out.println("--->>simpleSettingsTest<<--");
        AppContext appContext = Hasor.createAppContext("net/test/simple/core/_10_settings/simple-config.xml");
        Settings settings = appContext.getEnvironment().getSettings();
        //
        String myName = settings.getString("mySelf.myName");
        Hasor.logInfo("my Name is %s.", myName);
        //
        int myAge = settings.getInteger("mySelf.myAge");
View Full Code Here

TOP

Related Classes of net.hasor.core.AppContext

Copyright © 2018 www.massapicom. 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.