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


Java ClassPathXmlApplicationContext.getBean方法代码示例

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


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

示例1: 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:dachengxi,项目名称:EatDubbo,代码行数:20,代码来源:ConfigTest.java

示例2: testAnnotation

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Test
public void testAnnotation() {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
    try {
        ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-provider.xml");
        providerContext.start();
        try {
            ClassPathXmlApplicationContext consumerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/annotation-consumer.xml");
            consumerContext.start();
            try {
                AnnotationAction annotationAction = (AnnotationAction) consumerContext.getBean("annotationAction");
                String hello = annotationAction.doSayName("hello");
                assertEquals("annotation:hello", hello);
            } finally {
                consumerContext.stop();
                consumerContext.close();
            }
        } finally {
            providerContext.stop();
            providerContext.close();
        }
    } finally {
        exporter.unexport();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:27,代码来源:ConfigTest.java

示例3: 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:yunhaibin,项目名称:dubbox-hystrix,代码行数:25,代码来源:AsyncConsumer.java

示例4: contextInitialized

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent evt)
{
    log.debug("Load data");
    ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    InitServiceI initService = (InitServiceI) ctx
            .getBean("demoInitService");
    try
    {
        initService.init();
        // File file = new File(this.getClass().getClassLoader()
        // .getResource(("applicationContext.xml")).getFile());
        // SysConfig.Catalog_Project = file.getAbsolutePath().replace(
        // "applicationContext.xml", "");
    } catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:20,代码来源:InitDataListener.java

示例5: 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);
    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,代码行数:18,代码来源:QueryAndEncodeDatabaseAuthenticationHandlerTests.java

示例6: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            new String[]{"dubbo-comsumer.xml"});
    context.start();
    // obtain proxy object for remote invocation
    DemoService demoService = (DemoService) context.getBean("demoService");
    // execute remote invocation
    String hello = demoService.sayHello("world");
    // show the result
    System.out.println(hello);
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:12,代码来源:Consumer.java

示例7: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String config = GenericConsumer.class.getPackage().getName().replace('.', '/') + "/generic-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    IUserService userservice = (IUserService) context.getBean("userservice");
    User user = userservice.get(new Params("a=b"));
    System.out.println(user);
    System.in.read();
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:10,代码来源:GenericConsumer.java

示例8: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context =
            new ClassPathXmlApplicationContext("dubbo-demo-consumer.xml");
    context.start();
    Demo.Iface demo = (Demo.Iface) context.getBean("demoService");
    System.out.println(demo.echoI32(32));
    for (int i = 0; i < 10; i++) {
        System.out.println(demo.echoI32(i + 1));
    }
    context.close();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:12,代码来源:DubboDemoConsumer.java

示例9: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String config = CallbackConsumer.class.getPackage().getName().replace('.', '/') + "/callback-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    CallbackService callbackService = (CallbackService) context.getBean("callbackService");
    callbackService.addListener("foo.bar", new CallbackListener() {
        public void changed(String msg) {
            System.out.println("callback1:" + msg);
        }
    });
    System.in.read();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:13,代码来源:CallbackConsumer.java

示例10: testGenericServiceConfigThroughSpring

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Test
public void testGenericServiceConfigThroughSpring() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/generic-export.xml");
    try {
        ctx.start();
        ServiceConfig serviceConfig = (ServiceConfig) ctx.getBean("dubboDemoService");
        URL url = (URL)serviceConfig.getExportedUrls().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        ctx.destroy();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:ConfigTest.java

示例11: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String config = VersionConsumer.class.getPackage().getName().replace('.', '/') + "/version-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    VersionService versionService = (VersionService) context.getBean("versionService");
    for (int i = 0; i < 10000; i ++) {
        String hello = versionService.sayHello("world");
        System.out.println(hello);
        Thread.sleep(2000);
    }
    System.in.read();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:VersionConsumer.java

示例12: test_RpcContext_getUrls

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Test
public void test_RpcContext_getUrls() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(
            ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-long-waiting.xml");
    providerContext.start();

    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
                ConfigTest.class.getPackage().getName().replace('.', '/')
                        + "/init-reference-getUrls.xml");
        ctx.start();
        try {
            DemoService demoService = (DemoService) ctx.getBean("demoService");
            try {
                demoService.sayName("Haha");
                fail();
            } catch (RpcException expected) {
                assertThat(expected.getMessage(), containsString("Tried 3 times"));
            }

            assertEquals(3, RpcContext.getContext().getUrls().size());
        } finally {
            ctx.stop();
            ctx.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:31,代码来源:ConfigTest.java

示例13: initContext

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@BeforeTest
public void initContext() {
	context = new ClassPathXmlApplicationContext("classpath:test-commons-context.xml");
	consumer = context.getBean(JMSConsumer.class);
	searchPublisher = context.getBean(SearchPublisher.class);
	retryDir = context.getBean("retryDir", String.class);
	while (!consumer.isStarted()) {
		//wait until the consumers are started
	}
}
 
开发者ID:oneops,项目名称:oneops,代码行数:11,代码来源:SearchSenderTest.java

示例14: main

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    String config = JacksonConsumer.class.getPackage().getName().replace('.', '/') + "/jackson-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config);
    context.start();
    JacksonService jacksonService = (JacksonService) context.getBean("jacksonService");
    System.out.println("TEST: sayHello");
    String hello = jacksonService.sayHello("world");
    System.out.println(hello);

    System.out.println("TEST: testJacksonBean");
    JacksonBean jacksonBean = jacksonService.testJacksonBean(new JacksonBean(), new JacksonInnerBean());
    System.out.println(jacksonBean);

    System.out.println("TEST: testInheritBean");
    Inherit inherit = jacksonService.testInheritBean(new InheritBean(), new JacksonBean());
    System.out.println(inherit);

    System.out.println("TEST: testArray");
    int[] intArray = jacksonService.testArray(new int[]{1,2});
    System.out.println(Arrays.toString(intArray));

    System.out.println("TEST: testBeanArray");
    JacksonBean[] beanArray = jacksonService.testBeanArray(new JacksonBean[]{new JacksonBean(), new JacksonBean()});
    System.out.println(Arrays.toString(beanArray));

    System.out.println("TEST: testException");
    try {
        jacksonService.testException();
    } catch(Exception e){
        System.out.println("exception : " + e.getClass() + " : " + e.getMessage());
    }

    System.in.read();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:35,代码来源:JacksonConsumer.java

示例15: init

import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Before
public void init() {
	context = new ClassPathXmlApplicationContext("applicationContext.xml");
	service = context.getBean(NCacheService.class);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:6,代码来源:NRedisTest.java


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