当前位置: 首页>>代码示例>>Java>>正文


Java ClassPathXmlApplicationContext类代码示例

本文整理汇总了Java中org.springframework.context.support.ClassPathXmlApplicationContext的典型用法代码示例。如果您正苦于以下问题:Java ClassPathXmlApplicationContext类的具体用法?Java ClassPathXmlApplicationContext怎么用?Java ClassPathXmlApplicationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClassPathXmlApplicationContext类属于org.springframework.context.support包,在下文中一共展示了ClassPathXmlApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void main (String[] args){

    ConfigurableApplicationContext ac =
            new ClassPathXmlApplicationContext("/context.xml");
    PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);

    for (int i = 0; i < 10; i++) {
        Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
        if (message != null){
            System.out.println("==========="+i+"===========");
            SyndEntry entry = message.getPayload();
            System.out.println(entry.getAuthor());
            System.out.println(entry.getPublishedDate());
            System.out.println(entry.getTitle());
            System.out.println(entry.getUri());
            System.out.println(entry.getLink());
            System.out.println("======================");

        }
    }
    ac.close();


}
 
开发者ID:paulossjunior,项目名称:spring_integration_examples,代码行数:26,代码来源:Application.java

示例2: testBootstrapAndShutdown

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
public void testBootstrapAndShutdown() throws Exception
{
    // now bring up the bootstrap
    ApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML);
    
    // the folder should be gone
    assertFalse("Folder was not deleted by bootstrap", dir.exists());
    
    // now create the folder again
    dir.mkdir();
    assertTrue("Directory not created", dir.exists());
    
    // announce that the context is closing
    ctx.publishEvent(new ContextClosedEvent(ctx));
    
    // the folder should be gone
    assertFalse("Folder was not deleted by shutdown", dir.exists());
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:19,代码来源:RuntimeExecBeansTest.java

示例3: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
public static void main(String args[]){
    ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:applicationContext-service.xml"});
    HBaseService hbaseService = (HBaseService) ctx.getBean("HBaseService");
    GroupDataDao groupDatadao = (GroupDataDao) ctx.getBean("groupDataDao");
    GroupData groupData = new GroupData();
    try{
        groupData.setTime_id("test");
        groupData.setRecord_time("test");
        groupData.setAddr("test");
        groupData.setDataList("test");
        groupData.setProbe_id("test");
        groupData.setLat("test");
        groupData.setLon("test");
        groupData.setMmac("test");
        groupData.setWmac("test");
        groupData.setWssid("test");
        groupData.setRate("test");
        groupDatadao.save(groupData);
        System.out.println("Finish");
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:wanghan0501,项目名称:WiFiProbeAnalysis,代码行数:24,代码来源:HbaseInsertTest.java

示例4: testPageHelper

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Test
public void testPageHelper() {
	//创建一个spring容器
	ApplicationContext applicationContext = 
			new ClassPathXmlApplicationContext("classpath:spring/applicationContext-*.xml");
	//送spring容器中获得mapper代理对象
	TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class);
	//执行查询并分页
	TbItemExample tbItemExample = new TbItemExample();
	//分页处理
	PageHelper.startPage(1, 10);
	List<TbItem> list = itemMapper.selectByExample(tbItemExample);
	//获取商品列表
	for (TbItem tbItem : list) {
		System.out.println(tbItem.getTitle());
	}
	//取分页信息
	PageInfo<TbItem> pageInfo = new PageInfo<>(list);
	long total = pageInfo.getTotal();
	System.out.println("共有商品:" + total);
	
	
}
 
开发者ID:ChenXcc,项目名称:taotao-shop,代码行数:24,代码来源:TestPageHelper.java

示例5: delete

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Test
public void delete() {
	ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
	OrderRentHouseDao dao = (OrderRentHouseDao) ac.getBean("orderRentHouseDao");
	OrderRentHouse c = new OrderRentHouse();
	c.setOrderId(1);
	System.out.println(dao.deleteOrderRentHouse(c));
}
 
开发者ID:632team,项目名称:EasyHousing,代码行数:9,代码来源:OrderRentHouseTest.java

示例6: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String config = AsyncConsumer.class.getPackage().getName().replace('.', '/') + "/async-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    
    final AsyncService asyncService = (AsyncService)context.getBean("asyncService");
    
    Future<String> f = RpcContext.getContext().asyncCall(new Callable<String>() {
        public String call() throws Exception {
            return asyncService.sayHello("async call request");
        }
    });
    
    System.out.println("async call ret :" + f.get());
    
    RpcContext.getContext().asyncCall(new Runnable() {
        public void run() {
            asyncService.sayHello("oneway call request1");
            asyncService.sayHello("oneway call request2");
        }
    });
    
    System.in.read();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:25,代码来源:AsyncConsumer.java

示例7: testInitReference

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Test
public void testInitReference() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml");
    providerContext.start();
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml");
        ctx.start();
        try {
            DemoService demoService = (DemoService)ctx.getBean("demoService");
            assertEquals("say:world", demoService.sayName("world"));
        } finally {
            ctx.stop();
            ctx.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:20,代码来源:ConfigTest.java

示例8: testSystemPropertyOverrideMultiProtocol

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Test
public void testSystemPropertyOverrideMultiProtocol() throws Exception {
    System.setProperty("dubbo.protocol.dubbo.port", "20814");
    System.setProperty("dubbo.protocol.rmi.port", "10914");
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/override-multi-protocol.xml");
    providerContext.start();
    try {
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20814, dubbo.getPort().intValue());
        ProtocolConfig rmi = (ProtocolConfig) providerContext.getBean("rmi");
        assertEquals(10914, rmi.getPort().intValue());
    } finally {
        System.setProperty("dubbo.protocol.dubbo.port", "");
        System.setProperty("dubbo.protocol.rmi.port", "");
        providerContext.stop();
        providerContext.close();
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:19,代码来源:ConfigTest.java

示例9: setup

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Before
public void setup() throws Exception {


    final ClassPathXmlApplicationContext ctx = new
        ClassPathXmlApplicationContext("classpath:/jpaTestApplicationContext.xml");
    this.dataSource = ctx.getBean("dataSource", DataSource.class);

    this.handler = new SearchModeSearchDatabaseAuthenticationHandler();
    handler.setDataSource(this.dataSource);
    handler.setTableUsers("cassearchusers");
    handler.setFieldUser("username");
    handler.setFieldPassword("password");
    handler.afterPropertiesSet();

    final Connection c = this.dataSource.getConnection();
    final Statement s = c.createStatement();
    c.setAutoCommit(true);

    s.execute(getSqlInsertStatementToCreateUserAccount(0));
    for (int i = 0; i < 10; i++) {
        s.execute(getSqlInsertStatementToCreateUserAccount(i));
    }

    c.close();
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:27,代码来源:SearchModeSearchDatabaseAuthenticationHandlerTests.java

示例10: testXmlOverrideProperties

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Test
public void testXmlOverrideProperties() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/xml-override-properties.xml");
    providerContext.start();
    try {
        ApplicationConfig application = (ApplicationConfig) providerContext.getBean("application");
        assertEquals("demo-provider", application.getName());
        assertEquals("world", application.getOwner());
        
        RegistryConfig registry = (RegistryConfig) providerContext.getBean("registry");
        assertEquals("N/A", registry.getAddress());
        
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20813, dubbo.getPort().intValue());
        
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:21,代码来源:ConfigTest.java

示例11: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
public static void main(String[] args) {
	// TODO Auto-generated method stub

	try {
		// case1:
		ApplicationContext context = new ClassPathXmlApplicationContext(
				"beans_classpath.xml");
		// case2

		ApplicationContext context1 = new ClassPathXmlApplicationContext(
				new String[] { "beans_classpath.xml","beans_classpath1.xml" });
		System.out.println("container created successfully");
	} catch (BeansException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:19,代码来源:TestClasspathApplicationContext.java

示例12: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {

        final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "test-schduler.xml");

        InstanceFactory.setInstanceProvider(new SpringInstanceProvider(context));

        logger.info("TASK started....");
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

            @Override
            public void run() {
                logger.info("TASK Stoped....");
                context.close();
            }
        }));

        Scanner scan = new Scanner(System.in);
        String cmd = scan.next();
        if ("q".equals(cmd)) {
            scan.close();
            context.close();
        }

    }
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:26,代码来源:TaskServerNode2.java

示例13: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
public static void main(String[] args){
        ClassPathXmlApplicationContext cac = new ClassPathXmlApplicationContext("classpath*:worker2.xml","classpath*:spring/spring-worker-db.xml");
        cac.start();
        /*GenericApplicationContext gac = new GenericApplicationContext();
        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(gac);
        xmlReader.loadBeanDefinitions(new ClassPathResource("worker2.xml"));
        xmlReader.loadBeanDefinitions(new ClassPathResource("spring/spring-worker-db.xml"));
//        PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(gac);
//        propReader.loadBeanDefinitions(new ClassPathResource("db.properties"));
        gac.refresh();*/
        logger.info("Worker Server服务启动完成");
        // 启动本地服务,然后hold住本地服务
        synchronized (StartWorkerServer.class) {
            while (true) {
                try {
                    StartWorkerServer.class.wait();
                } catch (InterruptedException e) {
                }
            }
        }
    }
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:22,代码来源:StartWorkerServer.java

示例14: testRedisClient

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Test
public void testRedisClient() throws Exception {
    RedisRunner.RedisProcess run = new RedisRunner()
            .requirepass("do_not_use_if_it_is_not_set")
            .nosave()
            .randomDir()
            .run();
    try {
        ClassPathXmlApplicationContext context
                = new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_redis_client.xml");
        RedisClient redisClient = context.getBean(RedisClient.class);
        RedisConnection connection = redisClient.connect();
        Map<String, String> info = connection.sync(RedisCommands.INFO_ALL);
        assertThat(info, notNullValue());
        assertThat(info, not(info.isEmpty()));
        ((ConfigurableApplicationContext) context).close();
    } finally {
        run.stop();
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:SpringNamespaceWikiTest.java

示例15: Test2

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入依赖的package包/类
@Test
public void Test2(){
	ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");//��ʼ������
	BuildingDealDao buildingDealDao = (BuildingDealDao) ac.getBean("buildingDealDao");
	BuildingDeal u = new BuildingDeal();
	u.setAgentId(2);
	u.setBuildingDealPerPrice(100);
	u.setBuildingDealTime(new Date());
	u.setBuildingDealTotalPrice(100);
	u.setBuildingId(1);
	u.setBuildingLayout("����һ��");
	u.setUserId(1);
	u.setBuildingDealId(1);
	buildingDealDao.updateBuildingDeal(u);
	System.out.println("-------");
}
 
开发者ID:632team,项目名称:EasyHousing,代码行数:17,代码来源:TestBuildingDealDao.java


注:本文中的org.springframework.context.support.ClassPathXmlApplicationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。