Spring Framework ClassPathXmlApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ClassPathXmlApplicationContext class.

This code example shows how to use the following methods:getBean
 
 
	@Before 
	public void setUp() { 
		ClassPathXmlApplicationContext ctx =
				new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
 
		testImpl1 = (TestInterface) ctx.getBean("testImpl1");
		testImpl2 = (TestInterface) ctx.getBean("testImpl2");
		testAspectForTestImpl1 = (TestAspect) ctx.getBean("testAspectForTestImpl1");
		testAspectForAbstractTestImpl = (TestAspect) ctx.getBean("testAspectForAbstractTestImpl");
		testInterceptor = (TestInterceptor) ctx.getBean("testInterceptor");
 
		testAspectForTestImpl1.count = 0;
		testAspectForAbstractTestImpl.count = 0;
		testInterceptor.count = 0;
	} 
 
 
	@Test
8
CodeRank
This code example shows how to use the following methods:sleep, close, getBean, start, stop
		super(); 
	} 
 
	public static void main(String args[]) throws Exception {
 
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        		new String[] {"client-context.xml"});
 
        // By starting the context consumer-side endpoint, that receives 
        // callback messages, is started 
        context.start();
 
        // Here request-callback request to the service provider is performed 
        context.getBean("tester");
         
        Thread.sleep(120000);
 
        context.stop();
        context.close();
        System.exit(0);

8
CodeRank
This code example shows how to use the following methods:close, getBean, getBeanFactory
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getApplicationContextPath());
		ctx.close();
	} 
 
	public void testInvokeOnLazyInitBean() throws Exception {
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getApplicationContextPath());
		assertFalse(ctx.getBeanFactory().containsSingleton("testBean"));
		assertFalse(ctx.getBeanFactory().containsSingleton("testBean2"));
		try { 
			MBeanServer server = (MBeanServer) ctx.getBean("server");
			ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean2");
			String name = (String) server.getAttribute(oname, "Name");
			assertEquals("Invalid name returned", "foo", name);
		} 
		finally { 
			ctx.close();
		} 
	} 
 
	private String getApplicationContextPath() {
		return "org/springframework/jmx/export/lazyInit.xml"; 
8
CodeRank
This code example shows how to use the following methods:getBean
 
 
	@Before 
	public void setUp() { 
		ClassPathXmlApplicationContext ctx =
			new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
		highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect");
		lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect");
		highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice");
		lowPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("lowPrecedenceSpringAdvice");
		testBean = (ITestBean) ctx.getBean("testBean");
	} 
 
	// ========== end of test case set up, start of tests proper =================== 
 
	@Test
	public void testAdviceOrder() { 
		PrecedenceTestAspect.Collaborator collaborator = new PrecedenceVerifyingCollaborator();
		this.highPrecedenceAspect.setCollaborator(collaborator);
		this.lowPrecedenceAspect.setCollaborator(collaborator);
7
CodeRank
This code example shows how to use the following methods:sleep, getBean, start, stop
 
	@Test
	@Ignore 
	public void testOutbound() throws Exception{
		ClassPathXmlApplicationContext ac = 
			new ClassPathXmlApplicationContext("SftpOutboundTransferSample-ignored.xml", SftpOutboundTransferSample.class);
		ac.start();
		File file = new File("/Users/ozhurakousky/workspace-sts-2.3.3.M2/si/spring-integration/spring-integration-sftp/local-test-dir/foo.txt");
		if (file.exists()){
			Message<File> message = MessageBuilder.withPayload(file).build();
			MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
			inputChannel.send(message);
			Thread.sleep(2000);
		} 
		System.out.println("Done");
		ac.stop();
		 
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getBean
	private CallCountingInterceptor interceptor;
 
	@Before 
	public void setUp() { 
		ClassPathXmlApplicationContext ctx =
			new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
		testBean = (ITestBean) ctx.getBean("testBean");
		interceptor = (CallCountingInterceptor) ctx.getBean("interceptor");
	} 
 
	@Test
	public void testPointcutting() { 
		assertEquals("Count should be 0", 0, interceptor.getCount());
		testBean.getSpouses();
		assertEquals("Count should be 1", 1, interceptor.getCount());
		testBean.getSpouse();
		assertEquals("Count should be 1", 1, interceptor.getCount());
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:close, containsBean
 * @author Sam Brannen 
 */ 
public class ComponentScanParserTests { 
 
	private ClassPathXmlApplicationContext loadContext(String path) {
		return new ClassPathXmlApplicationContext(path, getClass());
	} 
 
 
	@Test
	public void aspectjTypeFilter() { 
		ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTests.xml");
		assertTrue(context.containsBean("fooServiceImpl"));
		assertTrue(context.containsBean("stubFooDao"));
		assertFalse(context.containsBean("scopedProxyTestBean"));
		context.close();
	} 
 
	@Test
	public void aspectjTypeFilterWithPlaceholders() { 
		System.setProperty("basePackage", "example.scannable, test");
8
CodeRank
This code example shows how to use the following methods:sleep, destroy, getBean
public class SpringExample 
{ 
   public static void main(String[] args) throws ExceptionSystem.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();
   } 
} 
7
CodeRank
This code example shows how to use the following methods:getBean, start
		assertEquals("**", response.getPayload()); 
	} 
 
	@Test
	public void returnAddressWithChannelReferenceAfterMultipleEndpoints() { 
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
				"returnAddressTests.xml", this.getClass());
		MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
		PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
		context.start();
		Message<String> message = MessageBuilder.withPayload("*")
				.setReplyChannel(replyChannel).build();
		channel1.send(message);
		Message<?> response = replyChannel.receive(3000);
		assertNotNull(response); 
		assertEquals("********", response.getPayload()); 
		PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
		assertNull(channel2.receive(0));
	} 
 

7
CodeRank
This code example shows how to use the following methods:sleep, close, getBean
 
		final String sourceFileName = "README.md";
		final String destinationFileName = sourceFileName +"_foo";
 
		final ClassPathXmlApplicationContext ac =
			new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml", SftpOutboundTransferSample.class);
		@SuppressWarnings("unchecked") 
		SessionFactory<LsEntry> sessionFactory = ac.getBean(CachingSessionFactory.class);
		RemoteFileTemplate<LsEntry> template = new RemoteFileTemplate<LsEntry>(sessionFactory);
		SftpTestUtils.createTestFiles(template); // Just the directory
 
		try { 
			final File file = new File(sourceFileName);
 
			Assert.isTrue(file.exists(), String.format("File '%s' does not exist.", sourceFileName));
 
			final Message<File> message = MessageBuilder.withPayload(file).build();
			final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
 
			inputChannel.send(message);

7
CodeRank