Package net.hasor.core

Examples of net.hasor.core.AppContext


*/
public class OnesAsyncEventTest {
    @Test
    public void onesAsyncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>onesAsyncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        String EventName = "MyEvent";
        //1.添加事件监听器
        ec.pushListener(EventName, new MyListener());
        //2.引发异步事件,虽然引发了10次事件但只有一次会被执行。
View Full Code Here


public class SystemVariablesTest {
    @Test
    public void systemVariablesTest() throws Exception {
        System.out.println("--->>systemVariablesTest<<--");
        //
        AppContext appContext = Hasor.createAppContext();
        Environment env = appContext.getEnvironment();
        //
        //设置属性
        System.setProperty("MyVar", "hello");
        env.refreshVariables();/*刷新变量列表*/
        System.out.println(env.getEnvVar("MyVar"));
View Full Code Here

*/
public class SyncEventTest {
    @Test
    public void syncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>syncEventTest<<--");
        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 AwareContextTest {
    @Test
    public void awareContextTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>awareContextTest<<--");
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                //由于init过程中无法取得 appContext对象,因此让Hasor在适当的时机将自身注入进去。
                AwareBean aware = apiBinder.autoAware(new AwareBean());
                //
                apiBinder.bindType(AwareBean.class).toInstance(aware);
                apiBinder.bindType(String.class).idWith("say").toInstance("Say Hello.");
            }
        });
        //
        AwareBean awareBean = appContext.getInstance(AwareBean.class);
        awareBean.foo();
    }
View Full Code Here

*/
public class OnesSyncEventTest {
    @Test
    public void onesAsyncEventTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>onesAsyncEventTest<<--");
        AppContext appContext = Hasor.createAppContext();
        EventContext ec = appContext.getEnvironment().getEventContext();
        //
        String EventName = "MyEvent";
        //1.添加事件监听器
        ec.pushListener(EventName, new MyListener());
        //2.引发异步事件,虽然引发了10次事件但只有一次会被执行。
View Full Code Here

*/
public class IocTest {
    @Test
    public void iocTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>iocTest<<--");
        AppContext appContext = Hasor.createAppContext(new Module() {
            public void loadModule(ApiBinder apiBinder) throws Throwable {
                apiBinder.bindType(UserBean.class);
                apiBinder.bindType(UserTypeBean.class);
            }
        });
        //
        UserBean userBean = appContext.getInstance(UserBean.class);
        //
        System.out.println(userBean.getUserType().getTypeID());
        Thread.sleep(1000);
    }
View Full Code Here

public class Simple_UpdateJDBCTest {
    @Test
    public void simple_UpdateJDBCTest() throws SQLException {
        System.out.println("--->>simple_UpdateJDBCTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
    }
View Full Code Here

public class Simple_InsertJDBCTest {
    @Test
    public void simple_InsertJDBCTest() throws SQLException {
        System.out.println("--->>simple_InsertJDBCTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        System.out.println(jdbc.queryForInt("select count(*) from TB_User where userUUID='deb4f4c8-5ba1-4f76-8b4a-c2be028bf57b'"));
        //
        String insertUser = "insert into TB_User values('deb4f4c8-5ba1-4f76-8b4a-c2be028bf57b','安妮.贝隆','belon','123','belon@hasor.net','2011-06-08 20:08:08');";
        jdbc.execute(insertUser);//执行插入语句
View Full Code Here

public class FindClassTest {
    @Test
    public void findClassTest() throws IOException, URISyntaxException, InterruptedException {
        System.out.println("--->>findClassTest<<--");
        //1.创建一个标准的 Hasor 容器。
        AppContext appContext = Hasor.createAppContext();
        //
        // 请注意: Hasor默认扫描的范围是、net.*,com.*,org.*。 如要自定义扫描范围有两种办法:
        //         1.通过hasor-config.xml配置文件配置。
        //         2.通过 ((AbstractEnvironment)appContext.getEnvironment()).setSpanPackage(...); 方法修改
        //
        //1.查找所有Hasor模块(实现了Module接口的类)。
        Set<Class<?>> facesFeature = appContext.getEnvironment().findClass(Module.class);
        Hasor.logInfo("find %s.", facesFeature);
        //2.查找AbstractAppContext的子类
        Set<Class<?>> subFeature = appContext.getEnvironment().findClass(AbstractAppContext.class);
        Hasor.logInfo("find %s.", subFeature);
    }
View Full Code Here

public class MapBatch_InsertJDBCTest {
    @Test
    public void baseInsertJDBCTest() throws SQLException {
        System.out.println("--->>baseInsertJDBCTest<<--");
        //
        AppContext app = Hasor.createAppContext("net/test/simple/db/jdbc-config.xml", new OneDataSourceWarp());
        JdbcTemplate jdbc = app.getInstance(JdbcTemplate.class);
        //
        String batchInsert = "insert into TB_User values(:ID,:Name,:Account,:Pwd,:Email,:RegTime);";
        //
        showUserCount(jdbc);//显示当前用户总数
        int count = 10;
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.