List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:org.dataconservancy.dcs.integration.main.FileRoundTripIT.java
@BeforeClass public static void createSampleFile() throws IOException { initFiles();/*from www .j a v a 2 s. c o m*/ ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] { "depositClientContext.xml", "classpath*:org/dataconservancy/config/applicationContext.xml" }); depositClient = (DepositClient) appContext.getBean("depositClient"); archive = (ArchiveStore) appContext.getBean("org.dataconservancy.archive.api.ArchiveStore"); DcsDeliverableUnit du = new DcsDeliverableUnit(); du.setId(templateDeliverableUnitId); du.setTitle("title"); DcsManifestation man = new DcsManifestation(); man.setId(templateManifestationId); man.setDeliverableUnit(templateDeliverableUnitId); template = new Dcp(); template.addDeliverableUnit(du); template.addManifestation(man); }
From source file:org.dataconservancy.dcs.integration.main.UpdateDepositIT.java
@BeforeClass public static void setup() throws IOException { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] { "depositClientContext.xml", "classpath*:org/dataconservancy/config/applicationContext.xml" }); depositClient = (DepositClient) appContext.getBean("depositClient"); }
From source file:org.entando.entando.aps.system.XmlWebApplicationContext.java
@Override public <T> T getBean(Class<T> requiredType) throws BeansException { T bean = null;//from ww w . j a va 2 s. co m try { bean = super.getBean(requiredType); } catch (Exception e) { List<ClassPathXmlApplicationContext> contexts = (List<ClassPathXmlApplicationContext>) this .getServletContext().getAttribute("pluginsContextsList"); if (contexts != null) { for (ClassPathXmlApplicationContext classPathXmlApplicationContext : contexts) { if (bean == null) { try { bean = classPathXmlApplicationContext.getBean(requiredType); return bean; } catch (Exception ex) { } } } } } return bean; }
From source file:org.entando.entando.aps.system.XmlWebApplicationContext.java
@Override public Object getBean(String name) throws BeansException { Object bean = null;//from ww w . j a va 2 s .co m try { bean = super.getBean(name); } catch (Exception e) { List<ClassPathXmlApplicationContext> contexts = (List<ClassPathXmlApplicationContext>) this .getServletContext().getAttribute("pluginsContextsList"); if (contexts != null) { for (ClassPathXmlApplicationContext classPathXmlApplicationContext : contexts) { if (bean == null) { try { bean = classPathXmlApplicationContext.getBean(name); return bean; } catch (Exception ex) { } } } } } return bean; }
From source file:org.eobjects.datacleaner.monitor.alertnotification.AlertNotificationServiceImplTest.java
public void testNotify() throws Exception { final File targetDir = new File("target/example_repo"); FileUtils.deleteDirectory(targetDir); FileUtils.copyDirectory(new File("src/test/resources/example_repo"), targetDir); final AtomicInteger counter = new AtomicInteger(); final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "context/application-context.xml"); final AlertNotificationServiceImpl alertNotificationService = (AlertNotificationServiceImpl) applicationContext .getBean(AlertNotificationService.class); alertNotificationService.getAlertNotifiers().add(new AlertNotifier() { @Override//w w w. j av a2 s. c o m public void onExecutionFinished(ExecutionLog execution, Ref<Map<AlertDefinition, Number>> activeAlerts, ResultContext result) { counter.incrementAndGet(); assertTrue(activeAlerts.get().isEmpty()); } }); TenantIdentifier tenant = new TenantIdentifier("tenant1"); JobIdentifier job = new JobIdentifier("product_profiling"); ScheduleDefinition schedule = new ScheduleDefinition(tenant, job, "orderdb"); ExecutionLog execution = new ExecutionLog(schedule, TriggerType.MANUAL); execution.setResultId("product_profiling-3.analysis.result.dat"); alertNotificationService.notifySubscribers(execution); assertEquals(1, counter.get()); applicationContext.close(); }
From source file:org.hyperic.bootstrap.HQServer.java
public static void main(String[] args) { int iReturnCode = -1; ClassPathXmlApplicationContext appContext = null; try {/*from w w w . j a v a 2s . c om*/ appContext = new ClassPathXmlApplicationContext( new String[] { "classpath*:/META-INF/spring/bootstrap-context.xml" }); } catch (Exception e) { System.err.println("Error initializing bootstrap class: " + e.toString() + " " + e.getMessage()); e.printStackTrace(); return; } HQServer server = appContext.getBean(HQServer.class); if ("start".equals(args[0])) { iReturnCode = server.start(); } else if ("stop".equals(args[0])) { server.stop(); iReturnCode = ShutdownType.NormalStop.exitCode(); //return ; } else { System.err.println("Usage: HQServer {start|stop}"); } //delegate the shutdown behavior to the ShutdownType strategies. final ShutdownType enumShutdownType = ShutdownType.reverseValueOf(iReturnCode); System.out.println( "[HQServer.main(" + args[0] + ")]: Shutdown of type '" + enumShutdownType + "' was request"); enumShutdownType.shutdown(); }
From source file:org.openspaces.itest.archive.ArchiveContainerTest.java
private void xmlTest(String relativeXmlName, int expectedBatchSize) throws InterruptedException { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(relativeXmlName); try {/*from ww w . j a v a 2 s .c o m*/ final MockArchiveOperationsHandler archiveHandler = context.getBean(MockArchiveOperationsHandler.class); final GigaSpace gigaSpace = context.getBean(org.openspaces.core.GigaSpace.class); ArchivePollingContainer container = getArchivePollingContainer(context); Assert.assertTrue("Expected archive container to be configured with use-fifo-grouping=true", container.isUseFifoGrouping()); test(archiveHandler, gigaSpace, container, expectedBatchSize); } finally { context.close(); } }
From source file:org.openspaces.itest.archive.ArchiveContainerTest.java
private ArchivePollingContainer getArchivePollingContainer(final ClassPathXmlApplicationContext context) { ArchivePollingContainer container;//from w ww . j a v a 2s. c o m try { container = context.getBean(ArchivePollingContainer.class); } catch (final Exception e) { final EventContainersBus eventContainersBus = AnnotationProcessorUtils.findBus(context); container = (ArchivePollingContainer) eventContainersBus.getEventContainers().iterator().next(); } return container; }
From source file:org.sakaiproject.coursemanagement.test.HibernateTestDataLoader.java
public static void main(String[] args) { ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext( new String[] { "spring-test.xml", "spring-config-test.xml" }); DataLoader loader = (DataLoader) ac.getBean(DataLoader.class.getName()); try {/* ww w.ja v a2 s . co m*/ loader.load(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.sipfoundry.sipxconfig.admin.dialplan.DialPlanContextImpl.java
/** * Resets the flexible dial plan to factory defaults. * * Loads default rules definition from bean factory file. *///from www . j a v a2s. com public DialPlan resetToFactoryDefault(String dialPlanBeanName, AutoAttendant operator) { removeAll(DialingRule.class); removeAll(DialPlan.class); getHibernateTemplate().flush(); DialPlan newDialPlan = null; // try loading region specific dialplan try { newDialPlan = (DialPlan) m_beanFactory.getBean(dialPlanBeanName); } catch (NoSuchBeanDefinitionException ex) { LOG.info(DIAL_PLAN + dialPlanBeanName + " not found"); } // region specific dial plan may be installed at runtime - we need to load its // corresponding dialrules.beans.xml if (newDialPlan == null) { try { String regionId = dialPlanBeanName.split("\\.")[0]; ClassPathXmlApplicationContext beanFactory = new ClassPathXmlApplicationContext( new String[] { "region_" + regionId + "/dialrules.beans.xml" }, m_applicationContext); newDialPlan = (DialPlan) beanFactory.getBean(dialPlanBeanName); LOG.info(DIAL_PLAN + dialPlanBeanName + " is installed"); } catch (Exception ex) { throw new RegionDialPlanException(ex); } } newDialPlan.setOperator(operator); getHibernateTemplate().save(newDialPlan); // Flush the session to cause the delete to take immediate effect. // Otherwise we can get name collisions on dialing rules when we load the // default dial plan, causing a DB integrity exception, even though the // collisions would go away as soon as the session was flushed. getHibernateTemplate().flush(); return newDialPlan; }