Java Code Examples for org.springframework.context.support.ClassPathXmlApplicationContext#start()

The following examples show how to use org.springframework.context.support.ClassPathXmlApplicationContext#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 2
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testProviderNestedService() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/provider-nested-service.xml");
    ctx.start();
    try {
        ServiceConfig<DemoService> serviceConfig = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig");
        assertNotNull(serviceConfig.getProvider());
        assertEquals(2000, serviceConfig.getProvider().getTimeout().intValue());
        
        ServiceConfig<DemoService> serviceConfig2 = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig2");
        assertNotNull(serviceConfig2.getProvider());
        assertEquals(1000, serviceConfig2.getProvider().getTimeout().intValue());
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example 3
Source File: Main.java    From mumu with Apache License 2.0 6 votes vote down vote up
/**
 * 分片
 */
public static void sharding() {
	ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
			"classpath:spring-jedis.xml");
	applicationContext.start();

	JedisClientShardImpl JedisClientShard = applicationContext
			.getBean(JedisClientShardImpl.class);
	for (int i = 0; i < 100; i++) {
		String set = JedisClientShard.set("userName"+i, ""+i);
		System.out.println(set);
	}

	System.out.println(JedisClientShard.get("userName"));
	applicationContext.close();
}
 
Example 4
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelayFixedTime() throws Exception {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-fixed-time.xml");
    ctx.start();
    try {
        List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNull(urls);
        int i = 0;
        while ((i++) < 60 && urls == null) {
            urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
            Thread.sleep(10);
        }
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20888/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
    } finally {
        ctx.stop();
        ctx.close();
        exporter.unexport();
    }
}
 
Example 5
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 6
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpringExtensionInject() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/spring-extension-inject.xml");
    ctx.start();
    try {
        MockFilter filter = (MockFilter) ExtensionLoader.getExtensionLoader(Filter.class).getExtension("mymock");
        assertNotNull(filter.getMockDao());
        assertNotNull(filter.getProtocol());
        assertNotNull(filter.getLoadBalance());
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example 7
Source File: MetadataLocalXmlProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/metadata-provider.xml");
    context.start();

    printServiceData();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 8
Source File: BasicConsumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
    context.start();

    DemoService demoService = context.getBean("demoService", DemoService.class);
    String hello = demoService.sayHello("world", 5000);
    System.out.println(hello);
}
 
Example 9
Source File: SimpleRegistryXmlProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    new EmbeddedZooKeeper(2181, false).start();

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/simplified-provider.xml");
    context.start();

    printServiceData();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 10
Source File: BasicConsumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
    context.start();

    DemoService demoService = context.getBean("demoService", DemoService.class);
    DemoService2 demoService2 = context.getBean("demoService2", DemoService2.class);

    String hello = demoService.sayHello("world");
    System.out.println(hello);

    String hello2 = demoService2.sayHello("world again");
    System.out.println(hello2);
}
 
Example 11
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpringExtensionInject() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/spring-extension-inject.xml");
    ctx.start();
    try {
        MockFilter filter = (MockFilter) ExtensionLoader.getExtensionLoader(Filter.class).getExtension("mymock");
        assertNotNull(filter.getMockDao());
        assertNotNull(filter.getProtocol());
        assertNotNull(filter.getLoadBalance());
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example 12
Source File: ThriftProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/thrift-provider.xml");
    context.start();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 13
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceClass() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-class.xml");
    ctx.start();
    try {
        DemoService demoService = refer("dubbo://127.0.0.1:20887");
        String hello = demoService.sayName("hello");
        assertEquals("welcome:hello", hello);
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example 14
Source File: BasicProvider.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
    context.start();

    System.out.println("dubbo service started");
    new CountDownLatch(1).await();
}
 
Example 15
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiProtocolError() {
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-error.xml");
        ctx.start();
        ctx.stop();
        ctx.close();
    } catch (BeanCreationException e) {
        assertTrue(e.getMessage().contains("Found multi-protocols"));
    }
}
 
Example 16
Source File: AsyncProvider.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    String config = AsyncProvider.class.getPackage().getName().replace('.', '/') + "/async-provider.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    System.in.read();
}
 
Example 17
Source File: Consumer.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/dubbo.consumer.xml","META-INF/spring/service.xml");
    context.start();
    context.getBean(Consumer.class).start();
}
 
Example 18
Source File: MergeProvider2.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    String config = MergeProvider2.class.getPackage().getName().replace('.', '/') + "/merge-provider2.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    System.in.read();
}
 
Example 19
Source File: AnnotationProvider.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    String config = AnnotationProvider.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    System.in.read();
}
 
Example 20
Source File: Provider.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
/**
 * To get ipv6 address to work, add
 * System.setProperty("java.net.preferIPv6Addresses", "true");
 * before running your application.
 */
public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo.provider.xml"});
    context.start();
    System.in.read(); // press any key to exit
}