List of usage examples for org.springframework.context ApplicationContext getBeanDefinitionNames
String[] getBeanDefinitionNames();
From source file:com.clican.pluto.fsm.engine.impl.EngineContextImpl.java
public void start() { if (log.isInfoEnabled()) { log.info("Begin to start Finiate State Machine Engine Context"); }/*from w ww . j av a2 s . c o m*/ for (Deploy deploy : deployList) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { deploy.getUrl() }, this.applicationContext); if (!sessionSpringMap.containsKey(deploy.getName())) { sessionSpringMap.put(deploy.getName(), new HashMap<Integer, ApplicationContext>()); } sessionSpringMap.get(deploy.getName()).put(deploy.getVersion(), context); // Lazy InitBean?? for (String name : context.getBeanDefinitionNames()) { context.getBean(name); } if ((lastVersionMap.containsKey(deploy.getName()) && lastVersionMap.get(deploy.getName()).compareTo(deploy.getVersion()) < 0) || !lastVersionMap.containsKey(deploy.getName())) { lastVersionMap.put(deploy.getName(), deploy.getVersion()); } } if (log.isInfoEnabled()) { log.info("The Finiate State Machine Engine Context has been started successfully."); } }
From source file:it.cilea.osd.jdyna.web.controller.ImportAnagraficaObject.java
/** Performa l'import da file xml di configurazioni di oggetti; * Sull'upload del file la configurazione dell'oggetto viene caricato come contesto di spring * e salvate su db./* w ww .j a v a 2s. c o m*/ */ @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object, BindException errors) throws RuntimeException, IOException { FileUploadConfiguration bean = (FileUploadConfiguration) object; MultipartFile file = (CommonsMultipartFile) bean.getFile(); File a = null; //creo il file temporaneo che sara' caricato come contesto di spring per caricare la configurazione degli oggetti a = File.createTempFile("jdyna", ".xml", new File(path)); file.transferTo(a); ApplicationContext context = null; try { context = new FileSystemXmlApplicationContext(new String[] { "file:" + a.getAbsolutePath() }); } catch (XmlBeanDefinitionStoreException exc) { //cancello il file dalla directory temporanea logger.warn("Error during the configuration import from file: " + file.getOriginalFilename(), exc); a.delete(); saveMessage(request, getText("action.file.nosuccess.upload", new Object[] { exc.getMessage() }, request.getLocale())); return new ModelAndView(getErrorView()); } //cancello il file dalla directory temporanea a.delete(); String[] tpDefinitions = context.getBeanDefinitionNames(); //getBeanNamesForType(tpClass); AnagraficaObject<P, TP> anagraficaObject = null; String idStringAnagraficaObject = request.getParameter("id"); Integer pkey = Integer.parseInt(idStringAnagraficaObject); anagraficaObject = applicationService.get(modelClass, pkey); //la variabile i conta le tipologie caricate con successo int i = 0; //la variabile j conta le tipologie non caricate int j = 0; for (String tpNameDefinition : tpDefinitions) { try { ImportPropertyAnagraficaUtil importBean = (ImportPropertyAnagraficaUtil) context .getBean(tpNameDefinition); anagraficaUtils.importProprieta(anagraficaObject, importBean); } catch (Exception ecc) { saveMessage(request, getText("action.file.nosuccess.metadato.upload", new Object[] { ecc.getMessage() }, request.getLocale())); j++; i--; } i++; } //pulisco l'anagrafica anagraficaObject.pulisciAnagrafica(); applicationService.saveOrUpdate(modelClass, anagraficaObject); saveMessage(request, getText("action.file.success.upload", new Object[] { new String("Totale Oggetti Caricati:" + (i + j) + "" + "[" + i + " caricate con successo/" + j + " fallito caricamento]") }, request.getLocale())); return new ModelAndView(getDetailsView()); }
From source file:test.com.azaptree.services.spring.application.SpringApplicationServiceTest.java
@Test public void testSpringApplicationService_configClasses() throws Exception { final String[] args = { "classpath:spring-application-service.xml" }; try {//from w w w . j ava 2 s. co m new Thread(new Runnable() { @Override public void run() { try { SpringApplicationService.main(args); } catch (Exception e) { e.printStackTrace(); } } }).start(); Thread.yield(); ApplicationContext ctx = SpringApplicationService.getApplicationContext(); while (ctx == null) { log.info("Waiting for ApplicationContext to initialize ..."); Thread.sleep(100l); ctx = SpringApplicationService.getApplicationContext(); } Assert.assertNotNull(ctx); final Properties props = ctx.getBean("systemProps", Properties.class); Assert.assertNotNull(props); Assert.assertFalse(CollectionUtils.isEmpty(props)); final Map<String, String> env = ctx.getBean("env", Map.class); Assert.assertNotNull(env); Assert.assertFalse(CollectionUtils.isEmpty(env)); log.info("bean count: {}", ctx.getBeanDefinitionCount()); for (String beanName : ctx.getBeanDefinitionNames()) { log.info("beanName: {}", beanName); } } finally { SpringApplicationService.shutdown(); } }
From source file:org.craftercms.commons.ebus.config.EBusBeanAutoConfiguration.java
@Override public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent) { ApplicationContext ctx = contextRefreshedEvent.getApplicationContext(); if (applicationContext != ctx) { return;/*from w w w .ja v a 2 s. c o m*/ } if (null == beanResolver) { beanResolver = new BeanFactoryResolver(ctx); } if (null == conversionService) { try { conversionService = ctx.getBean(ConsumerBeanAutoConfiguration.REACTOR_CONVERSION_SERVICE_BEAN_NAME, ConversionService.class); } catch (BeansException be) { // TODO: log that conversion service is not found. } } synchronized (this) { if (started) { return; } Set<Method> methods; Class<?> type; for (String beanName : ctx.getBeanDefinitionNames()) { type = ctx.getType(beanName); methods = findHandlerMethods(type, LISTENER_METHOD_FILTER); if (methods != null && methods.size() > 0) { wireBean(ctx.getBean(beanName), methods); } } started = true; } }
From source file:net.bull.javamelody.TestMonitoringFilter.java
/** Test. * @throws ServletException e// w w w. j ava 2 s . c om * @throws IOException e */ @Test public void testDoMonitoringWithPartsForSystemActions() throws ServletException, IOException { final Map<HttpParameter, String> parameters = new HashMap<HttpParameter, String>(); setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, TRUE); parameters.put(HttpParameter.PART, HttpPart.PROCESSES.getName()); monitoring(parameters); monitorJdbcParts(parameters); // il ne faut pas faire un heapHisto sans thread comme dans TestHtmlHeapHistogramReport // parameters.put(HttpParameter.PART, HttpPart.HEAP_HISTO.getName()); // monitoring(parameters); monitoringSessionsPart(parameters); parameters.put(HttpParameter.PART, HttpPart.WEB_XML.getName()); monitoring(parameters, false); parameters.put(HttpParameter.PART, HttpPart.POM_XML.getName()); monitoring(parameters, false); parameters.put(HttpParameter.PART, HttpPart.JNDI.getName()); monitoring(parameters); parameters.put(HttpParameter.PART, HttpPart.MBEANS.getName()); monitoring(parameters); final ApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "net/bull/javamelody/monitoring-spring.xml", }); context.getBeanDefinitionNames(); parameters.put(HttpParameter.PART, HttpPart.SPRING_BEANS.getName()); monitoring(parameters); setProperty(Parameter.SAMPLING_SECONDS, "60"); setUp(); parameters.put(HttpParameter.PART, HttpPart.HOTSPOTS.getName()); monitoring(parameters); parameters.remove(HttpParameter.PART); parameters.put(HttpParameter.JMX_VALUE, "java.lang:type=OperatingSystem.ProcessCpuTime"); monitoring(parameters); parameters.remove(HttpParameter.JMX_VALUE); }
From source file:test.com.azaptree.services.spring.application.SpringApplicationServiceTest.java
@Test public void testSpringApplicationService() throws Exception { final String[] args = { "classpath:spring-application-service.xml" }; try {/* ww w . ja va 2 s. c o m*/ new Thread(new Runnable() { @Override public void run() { try { SpringApplicationService.main(args); } catch (Exception e) { e.printStackTrace(); } } }).start(); Thread.yield(); ApplicationContext ctx = SpringApplicationService.getApplicationContext(); while (ctx == null) { log.info("Waiting for ApplicationContext to initialize ..."); Thread.sleep(100l); ctx = SpringApplicationService.getApplicationContext(); } Assert.assertNotNull(ctx); final Properties props = ctx.getBean("systemProps", Properties.class); Assert.assertNotNull(props); Assert.assertFalse(CollectionUtils.isEmpty(props)); Assert.assertEquals(props.getProperty("app.env"), "DEV"); final Map<String, String> env = ctx.getBean("env", Map.class); Assert.assertNotNull(env); Assert.assertFalse(CollectionUtils.isEmpty(env)); final Map<String, String> environment = ctx.getBean("environment", Map.class); Assert.assertNotNull(environment); Assert.assertFalse(CollectionUtils.isEmpty(environment)); log.info("bean count: {}", ctx.getBeanDefinitionCount()); for (String beanName : ctx.getBeanDefinitionNames()) { log.info("beanName: {}", beanName); } } finally { SpringApplicationService.shutdown(); } }
From source file:org.xmlactions.web.conceal.HttpPager.java
public SessionExecContext setupExecContext(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException { ApplicationContext applicationContext = getApplicationContext(request.getSession(true).getServletContext()); SessionExecContext execContext = (SessionExecContext) applicationContext .getBean(ActionConst.EXEC_CONTEXT_BEAN_REF); new CreateHandyParams(execContext); // Make it available for the scope of this request. RequestExecContext.set(execContext); execContext.setApplicationContext(applicationContext); execContext.put(ActionConst.WEB_REAL_PATH_BEAN_REF, realPath); execContext.put(ActionConst.PAGE_NAMESPACE_BEAN_REF, nameSpace); execContext.setSession(request.getSession(true)); execContext.loadFromPersistence();//from w ww.ja v a2 s. co m execContext.addNamedMap(IExecContext.PERSISTENCE_MAP, execContext.getPersistenceMap()); new CreateUserParams(execContext); // FIXME - will want to remove the addNamedMap("request") Map<String, Object> params = new HtmlRequestMapper(-1).getRequestParamsAsMap(request); if (params != null) { execContext.addNamedMap(PagerWebConst.REQUEST, params); } List<HttpParam> paramList = new HtmlRequestMapper(-1).getRequestParamsAsVector(request); if (paramList != null) { execContext.put(PagerWebConst.REQUEST_LIST, paramList); } String pageName = request.getServletPath(); // remove the leading slash/ execContext.put(PagerWebConst.PAGE_NAME, (pageName.length() > 1 ? pageName.substring(1) : pageName)); execContext.put(PagerWebConst.PAGE_URI, request.getRequestURI()); execContext.put(PagerWebConst.PAGE_URL, request.getRequestURL().toString()); execContext.put(PagerWebConst.PAGE_SERVER_NAME, request.getServerName()); String appName = getAppName(request.getRequestURI()); execContext.put(PagerWebConst.PAGE_APP_NAME, appName); if (StringUtils.isEmpty(appName)) { execContext.put(ActionConst.WEB_ROOT_BEAN_REF, ""); } else { execContext.put(ActionConst.WEB_ROOT_BEAN_REF, "/" + appName); } execContext.put(PagerWebConst.HTTP_REQUEST, request); execContext.put(PagerWebConst.HTTP_RESPONSE, response); execContext.put(PagerWebConst.HTTP_SESSION, request.getSession(true)); execContext.put(PagerWebConst.EXEC_CONTEXT, execContext); // log.debug(((PropertyContainer) // webApplicationContext.getBean("readOnlyProperties")).get("user.home")); log.debug("nameSpace:" + nameSpace); log.debug("Real Path:" + realPath); log.debug("bean count:" + execContext.getApplicationContext().getBeanDefinitionCount()); for (String beanName : applicationContext.getBeanDefinitionNames()) { log.debug("bean:" + beanName); execContext.put(beanName, applicationContext.getBean(beanName)); } execContext.addNamedMap(PagerWebConst.REQUEST_HEADERS, HttpSessionInfo.getRequestHeaders(request)); log.info("ExecContext size:" + execContext.size()); return execContext; }
From source file:org.kuali.coeus.sys.impl.service.SpringBeanConfigurationTest.java
/** * Apply a void function to each spring bean available in each spring context available from each spring resource loader. * * @param function the function to apply * @param ignoreCreationException whether to ignore exception that occurs when creating a bean *///w ww . j a v a2 s .c om private void toEachSpringBean(VoidFunction function, boolean ignoreCreationException) { Map<QName, List<KeyValue<String, Exception>>> failedBeans = new HashMap<>(); for (SpringResourceLoader r : springResourceLoaders) { ApplicationContext context = r.getContext(); for (String name : context.getBeanDefinitionNames()) { if (process(name)) { try { function.r(context, name); } catch (BeanIsAbstractException e) { //ignore since the bean can't be created } catch (BeanCreationException e) { //if there is no way to ignore creation errors all tests will fail even if one bean is bad regardless of the type //we do want this type of failure to be tested by at least one test method but not all tests if (!ignoreCreationException) { LOG.error( "unable to create bean " + name + (context instanceof ConfigurableWebApplicationContext ? " for locations " + Arrays .asList(((ConfigurableWebApplicationContext) context) .getConfigLocations()) : ""), e); throw e; } } catch (RuntimeException e) { LOG.error("failed to execute function for bean " + name + (context instanceof ConfigurableWebApplicationContext ? " for locations " + Arrays.asList( ((ConfigurableWebApplicationContext) context).getConfigLocations()) : ""), e); List<KeyValue<String, Exception>> rlFailures = failedBeans.get(r.getName()); if (rlFailures == null) { rlFailures = new ArrayList<>(); } rlFailures.add(new DefaultKeyValue<String, Exception>(name, e)); failedBeans.put(r.getName(), rlFailures); } } } } Assert.assertTrue("the following beans failed to retrieve " + failedBeans, failedBeans.isEmpty()); }
From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java
@Test // DATACMNS-330 public void registersBasicBeanDefinitions() throws Exception { ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class); List<String> names = Arrays.asList(context.getBeanDefinitionNames()); assertThat(names).contains("pageableResolver", "sortResolver"); assertResolversRegistered(context, SortHandlerMethodArgumentResolver.class, PageableHandlerMethodArgumentResolver.class); }
From source file:org.springframework.data.web.config.EnableSpringDataWebSupportIntegrationTests.java
@Test // DATACMNS-330 public void registersHateoasSpecificBeanDefinitions() throws Exception { ApplicationContext context = WebTestUtils.createApplicationContext(SampleConfig.class); List<String> names = Arrays.asList(context.getBeanDefinitionNames()); assertThat(names).contains("pagedResourcesAssembler", "pagedResourcesAssemblerArgumentResolver"); assertResolversRegistered(context, PagedResourcesAssemblerArgumentResolver.class); }