Package net.hasor.core

Examples of net.hasor.core.AppContext


public class UserControllerTest {
    @Test
    public void userControllerTest() throws Throwable {
        System.out.println("--->>userControllerTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                /*绑定一个接口的实现类*/
                apiBinder.installModule(new ControllerModule());
            }
        });
        //
        RootController root = appContext.getInstance(RootController.class);
        Map<String, String> data = new HashMap<String, String>();
        data.put("userID", "zyc");
        //
        root.findMapping("/users/@add").invoke(data);
        root.findMapping("/users/@del").invoke(data);
View Full Code Here


*/
public class UseMoreDataSource {
    @Test
    public void useMoreDataSource() throws SQLException, IOException {
        //1.构建AppContext
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new MoreDataSourceWarp());
        //2.取得JDBC操作接口
        JdbcTemplate mJDBC = app.getInstance("mysql");
        JdbcTemplate hJDBC = app.getInstance("hsql");
        //3.初始化表
        this.initData(mJDBC, hJDBC);
        //
        System.out.println("MySQL User Count :" + mJDBC.queryForInt("select count(*) from TB_User"));
        System.out.println("HSQL User Count :" + hJDBC.queryForInt("select count(*) from TB_User"));
View Full Code Here

        }
    }
    protected BindInfoFactory getBindInfoFactory() {
        //
        if (this.factoryProvider == null) {
            final AppContext app = this;
            this.factoryProvider = new FactoryProvider(null) {
                protected BindInfoFactory getBindInfoFactory() {
                    HasorRegisterFactory factory = new HasorRegisterFactory();
                    factory.setAppContext(app);
                    return factory;
View Full Code Here

public class ControllerTest {
    @Test
    public void controllerTest() throws Throwable {
        System.out.println("--->>controllerTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                /*绑定一个接口的实现类*/
                apiBinder.installModule(new ControllerModule());
            }
        });
        //
        RootController root = appContext.getInstance(RootController.class);
        //F
        root.findMapping("/oper/add").invoke();
        root.findMapping("/oper/del").invoke();
        //
    }
View Full Code Here

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

public class InterfaceBindTest {
    @Test
    public void faceBindTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>faceBindTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                /*绑定一个接口的实现类*/
                apiBinder.bindType(PojoInfo.class).to(PojoBean.class);
            }
        });
        //
        //通过接口获取绑定的Bean
        PojoInfo myBean2 = appContext.getInstance(PojoInfo.class);
        System.out.println(myBean2.getName() + "\t" + myBean2);
    }
View Full Code Here

public class ScopeTest {
    @Test
    public void scopeTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>scopeTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                MyScope myScope1 = new MyScope();
                //
                apiBinder.bindType(PojoBean.class).nameWith("myBean1").toScope(myScope1);
            }
        });
        //
        PojoBean myBean = null;
        myBean = appContext.findBindingBean("myBean1", PojoBean.class);
        System.out.println("Scope 1 : " + myBean.getName() + myBean);
        myBean = appContext.findBindingBean("myBean1", PojoBean.class);
        System.out.println("Scope 1 : " + myBean.getName() + myBean);
    }
View Full Code Here

public class TypeBindTest {
    @Test
    public void typeBindTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>typeBindTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                /*绑定类型到Hasor*/
                apiBinder.bindType(PojoBean.class);
            }
        });
        //
        //
        //通过绑定的类型获取Bean
        PojoBean myBean1 = appContext.getInstance(PojoBean.class);
        System.out.println(myBean1.getName() + "\t" + myBean1);
    }
View Full Code Here

public class Entity_QueryTest {
    @Test
    public void entity_QueryTest() throws SQLException {
        System.out.println("--->>entity_QueryTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        List<TB_User> userList = jdbc.queryForList("select * from TB_User", TB_User.class);
        HasorUnit.printObjectList(userList);
    }
View Full Code Here

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