List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:com.ryantenney.metrics.spring.RegisterElementTest.java
@Test public void testRegisterMetrics() { ClassPathXmlApplicationContext ctx = null; try {//from w w w .jav a 2 s .c o m ctx = new ClassPathXmlApplicationContext("classpath:register-element-test.xml"); MetricRegistry registry = ctx.getBean(MetricRegistry.class); Assert.assertTrue(registry.getMetrics().size() > 0); for (String metricName : registry.getMetrics().keySet()) { Assert.assertTrue(metricName.startsWith("jvm.")); } } finally { if (ctx != null) { ctx.close(); } } }
From source file:nats.client.spring.NatsFactoryBeanTest.java
@Test public void annotationConfig() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "annotationConfigContext.xml"); try {// w w w . j a v a 2 s .c o m final Nats nats = context.getBean(Nats.class); Assert.assertNotNull(nats); } finally { context.close(); } }
From source file:nz.co.senanque.madura.configuration.ConfigNamespaceTest.java
@Test public void testSpringConfig() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( getConfigLocations());/* w ww . j av a 2s.c om*/ Object hs1 = applicationContext.getBean("component.sourcedir"); assertTrue("mysourcedir".equals(hs1.toString())); Object hs2 = applicationContext.getBean("component1.sourcedir"); System.out.println(hs2.toString()); assertTrue("mysourcedir".equals(hs2.toString())); URL url = (URL) applicationContext.getBean("myurl"); assertTrue("http://localhost:8080/jjj".equals(url.toString())); System.out.println(url.toString()); MyTestBean myTestBean2 = (MyTestBean) applicationContext.getBean("m"); assertTrue("http://localhost:8080/jjj".equals(myTestBean2.getUrl().toString())); // Configuration configuration = (Configuration)applicationContext.getBean("configuration"); Object doc = applicationContext.getBean("test1"); MyTestBean myTestBean = (MyTestBean) applicationContext.getBean("test2"); assertTrue(myTestBean.getA().equals("XYZ")); myTestBean.setA("12345"); assertTrue(myTestBean.getA().equals("12345")); List sampleList = (List) applicationContext.getBean("sampleList"); assertEquals(2, sampleList.size()); // applicationContext.refresh(); ManagedReloadingStrategy reloadingStrategy = (ManagedReloadingStrategy) applicationContext .getBean("reloadingStrategy"); reloadingStrategy.refresh(); MyTestBean myTestBean1 = (MyTestBean) applicationContext.getBean("test2"); assertTrue(myTestBean1.getA().equals("XYZ")); }
From source file:br.com.pense.produto.controller.DescricaoAnuncioTest.java
@Test public void CarregamentoOntologia() { System.out.println(">>> CarregamentoOntologia"); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "applicationContext-semantic.xml"); engImoveis = (SemanticEngineImoveis) context.getBean("engineSemantica"); }
From source file:org.constretto.spring.assembly.AssemblyWithAspectsTest.java
private void loadContextAndInjectConfigurationService() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "org/constretto/spring/assembly/AssemblyWithAspectsTest-context.xml"); configurationService = (ConfigurationService) ctx.getBean("configurationService"); }
From source file:org.constretto.spring.assembly.AssemblyResolverStrategyTest.java
private void loadContextAndInjectConfigurationService() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "org/constretto/spring/assembly/AssemblyResolverStrategyTest-context.xml"); configurationService = (ConfigurationService) ctx.getBean("configurationService"); }
From source file:com.opengsn.controller.manager.FacilityManagerClient.java
public FacilityManagerClient() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "webapp/WEB-INF/applicationContext.xml" }); facilityMgr = (IFacilityManager) context.getBean("facilityManagerClient"); }
From source file:org.constretto.spring.assembly.AutowiringWithScopedServicesTest.java
private void loadContextAndInjectConfigurationService() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "org/constretto/spring/assembly/AutowiringWithScopedServicesTest-context.xml"); configurationService = (ConfigurationService) ctx.getBean("configurationService"); }
From source file:net.sf.jdbcwrappers.spring.SpringTest.java
@Test public void test() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "net/sf/jdbcwrappers/spring/beans.xml"); try {// w ww . j a v a 2 s . co m DataSource ds = (DataSource) context.getBean("dataSource"); assertTrue(Proxy.getInvocationHandler(ds) instanceof TrimmingDelegateInvocationHandler); // Attempt to get a connection ds.getConnection().close(); } finally { context.close(); } }
From source file:org.constretto.spring.assembly.AssemblyWithDefaultsTest.java
private void loadContextAndInjectConfigurationService() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "org/constretto/spring/assembly/AssemblyWithDefaultsTest-context.xml"); configurationService = (ConfigurationService) ctx.getBean("configurationService"); }