下面列出了org.springframework.context.support.ClassPathXmlApplicationContext#destroy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String[] args) {
try {
ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/multiport/thrift-consumer-multiapi.xml");
HelloService.Iface userService = (HelloService.Iface) beanFactory.getBean("helloService");
System.out.println(userService.sayHello("Emma"));
Echo.Iface echo = (Echo.Iface) beanFactory.getBean("echoService");
System.out.println(echo.echo("Hello world"));
beanFactory.destroy();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
@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();
}
}
public static void main(String[] args) {
try {
ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/zkmock/thrift-consumer.xml");
HelloService.Iface userservice = (HelloService.Iface) beanFactory.getBean("helloService");
System.out.println(userservice.sayHello("Emma"));
beanFactory.destroy();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/multirole/thrift-multiroles.xml");
HelloService.Iface userservice = (HelloService.Iface) beanFactory.getBean("helloService");
System.out.println(userservice.sayHello("Emma"));
beanFactory.destroy();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/simple/thrift-consumer.xml");
HelloService.Iface userService = (HelloService.Iface) beanFactory.getBean("helloService");
System.out.println(userService.sayHello("OCTO"));
beanFactory.destroy();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext("thrift/zkregistry/thrift-consumer.xml");
HelloService.Iface userService = (HelloService.Iface) beanFactory.getBean("helloService");
System.out.println(userService.sayHello("Emma"));
beanFactory.destroy();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws TException, InterruptedException, IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
final Echo.Iface client = context.getBean("clientProxy", Echo.Iface.class);
Thread[] threads = new Thread[num];
for (int i = 0; i < num; i++) {
final int finalI = i;
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
String result = null;
Random random = new Random();
for (int j = 0; j < num; j++) {
try {
result = client.echo("hello" + finalI + "," + j);
Thread.sleep(random.nextInt(100));
} catch (Exception e) {
e.printStackTrace();
}
assert ("echo: hello" + finalI + "," + j).equals(result);
}
}
});
threads[i].start();
}
for (Thread t : threads) {
t.join();
}
context.destroy();
System.exit(0);
}
@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();
}
}
@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();
}
}
@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();
}
}
@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();
}
}
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws Exception If example execution failed.
*/
public static void main(String[] args) throws Exception {
System.out.println();
System.out.println(">>> Spring bean example started.");
// Initialize Spring factory.
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext("org/apache/ignite/examples/misc/springbean/spring-bean.xml");
try {
// Get ignite from Spring (note that local cluster node is already started).
Ignite ignite = (Ignite)ctx.getBean("mySpringBean");
// Execute any method on the retrieved ignite instance.
ExecutorService exec = ignite.executorService();
Future<String> res = exec.submit(new Callable<String>() {
@Override public String call() throws Exception {
System.out.println("Hello world!");
return null;
}
});
// Wait for callable completion.
res.get();
System.out.println(">>>");
System.out.println(">>> Finished executing Ignite \"Spring bean\" example.");
System.out.println(">>> You should see printed out of 'Hello world' on one of the nodes.");
System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
System.out.println(">>>");
}
finally {
// Stop local cluster node.
ctx.destroy();
}
}
public static void main(String[] args) throws Exception {
System.out.println("Creating bean factory...");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring-jms-beans.xml"});
MessageSender sender = (MessageSender) context.getBean("MessageSender");
System.out.println("Sending message...");
sender.send("Hello world");
Thread.sleep(100);
context.destroy();
}
@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();
}
}
public static void main(String[] args) throws InterruptedException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"springContext.xml"});
log.debug("\n\n\n");
Thread.sleep(5000);
log.debug("Destroying context...");
context.destroy();
}