本文整理汇总了Java中org.springframework.context.support.ClassPathXmlApplicationContext.close方法的典型用法代码示例。如果您正苦于以下问题:Java ClassPathXmlApplicationContext.close方法的具体用法?Java ClassPathXmlApplicationContext.close怎么用?Java ClassPathXmlApplicationContext.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.context.support.ClassPathXmlApplicationContext
的用法示例。
在下文中一共展示了ClassPathXmlApplicationContext.close方法的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();
}
}
示例2: testProviderNestedService
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@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();
}
}
示例3: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"test-kafka-consumer.xml");
logger.info("Kafka Consumer started....");
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
logger.info("Kafka Consumer Stoped....");
context.close();
}
}));
Scanner scan = new Scanner(System.in);
String cmd = scan.next();
if ("q".equalsIgnoreCase(cmd)) {
context.close();
scan.close();
}
}
示例4: testFailureModeOfMissingCommand
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public void testFailureModeOfMissingCommand()
{
File dir = new File(DIR);
dir.mkdir();
assertTrue("Directory not created", dir.exists());
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML);
try
{
RuntimeExec failureExec = (RuntimeExec) ctx.getBean("commandFailureGuaranteed");
assertNotNull(failureExec);
// Execute it
ExecutionResult result = failureExec.execute();
assertEquals("Expected first error code in list", 666, result.getExitValue());
}
finally
{
ctx.close();
}
}
示例5: testDeprecatedSetCommandMap
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public void testDeprecatedSetCommandMap() throws Exception
{
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML);
try
{
RuntimeExec deprecatedExec = (RuntimeExec) ctx.getBean("commandCheckDeprecatedSetCommandMap");
assertNotNull(deprecatedExec);
// Execute it
deprecatedExec.execute();
}
finally
{
ctx.close();
}
// The best we can do is look at the log manually
logger.warn("There should be a warning re. the use of deprecated 'setCommandMap'.");
}
示例6: 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();
}
}
示例7: test_returnSerializationFail
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Test
public void test_returnSerializationFail() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-UnserializableBox.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");
try {
demoService.getBox();
fail();
} catch (RpcException expected) {
assertThat(expected.getMessage(), containsString("must implement java.io.Serializable"));
}
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
示例8: 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();
}
}
示例9: testDelayOnInitialized
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Test
public void testDelayOnInitialized() throws Exception {
SimpleRegistryService registryService = new SimpleRegistryService();
Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4548, registryService);
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/delay-on-initialized.xml");
//ctx.start();
try {
List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20883/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
} finally {
ctx.stop();
ctx.close();
exporter.unexport();
}
}
示例10: 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();
}
}
示例11: testSystemPropertyOverrideXmlDefault
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testSystemPropertyOverrideXmlDefault() throws Exception {
System.setProperty("dubbo.application.name", "sysover");
System.setProperty("dubbo.application.owner", "sysowner");
System.setProperty("dubbo.registry.address", "N/A");
System.setProperty("dubbo.protocol.name", "dubbo");
System.setProperty("dubbo.protocol.port", "20819");
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override-default.xml");
providerContext.start();
try {
ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig");
assertEquals("sysover", service.getApplication().getName());
assertEquals("sysowner", service.getApplication().getOwner());
assertEquals("N/A", service.getRegistry().getAddress());
assertEquals("dubbo", service.getProtocol().getName());
assertEquals(20819, service.getProtocol().getPort().intValue());
} finally {
System.setProperty("dubbo.application.name", "");
System.setProperty("dubbo.application.owner", "");
System.setProperty("dubbo.registry.address", "");
System.setProperty("dubbo.protocol.name", "");
System.setProperty("dubbo.protocol.port", "");
providerContext.stop();
providerContext.close();
}
}
示例12: main
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
public static void main(String[] args) {
// 运行main启动服务前, 打开application-context-test.xml的dubbo服务注释
// <import resource="classpath:spring/dubbo-pay-provider.xml" />
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "application-context-test.xml" });
context.start();
System.out.println("按回车键退出");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
context.close();
}
示例13: 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();
}
示例14: testMultiProtocol
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@Test
public void testMultiProtocol() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml");
ctx.start();
try {
DemoService demoService = refer("dubbo://127.0.0.1:20881");
String hello = demoService.sayName("hello");
assertEquals("say:hello", hello);
} finally {
ctx.stop();
ctx.close();
}
}
示例15: testMultiProtocolError
import org.springframework.context.support.ClassPathXmlApplicationContext; //导入方法依赖的package包/类
@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"));
}
}