List of usage examples for org.springframework.context ApplicationContext getBeanDefinitionNames
String[] getBeanDefinitionNames();
From source file:com.bsb.cms.commons.web.SpringContextUtil.java
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { inStance.ctx = applicationContext;/*from w w w.j a v a 2 s . c om*/ if (LOG.isDebugEnabled()) { String[] beans = applicationContext.getBeanDefinitionNames(); for (String beanName : beans) { LOG.debug("?beanName--->" + beanName); } } }
From source file:com.freebox.engeneering.application.system.webflow.spring.SpringFlowControllerContextLoader.java
/** * Scans beans annotated with State annotation and binds them to state context. * * @param context the spring application context *///from w w w . j a v a 2 s . c om @SuppressWarnings("rawtypes") public void load(ApplicationContext context) { long start = System.currentTimeMillis(); final String[] beanDefinitionNames = context.getBeanDefinitionNames(); for (String beanDefinitionName : beanDefinitionNames) { if (beanDefinitionName.endsWith("Context")) { final Object bean = context.getBean(beanDefinitionName); final Method[] methods = bean.getClass().getMethods(); for (Method method : methods) { final State state = AnnotationUtils.findAnnotation(method, State.class); if (state != null) { final String[] stateArray = state.value(); for (String stateName : stateArray) { final Object bean1 = context.getBean(method.getName()); final Placeholder placeholder = AnnotationUtils.findAnnotation(method, Placeholder.class); if (placeholder != null) { stateContext.bindController(stateName, placeholder.value(), method.getName()); } if (bean1 instanceof LayoutController) { stateContext.bindLayoutController(stateName, (LayoutController) bean1); } } } } } } long end = System.currentTimeMillis(); LOGGER.info("took time: " + ((end - start) / 1000) + " seconds."); }
From source file:org.danann.cernunnos.spring.ApplicationContextTask.java
public void perform(TaskRequest req, TaskResponse res) { URL loc = resource.evaluate(req, res); ApplicationContext beans = getApplicationContext(loc, (Boolean) cache.evaluate(req, res)); for (String name : beans.getBeanDefinitionNames()) { try {/* w w w .j a v a 2s . c o m*/ res.setAttribute(name, beans.getBean(name)); } catch (BeanIsAbstractException biae) { // This is normal -- we can't ask for abstract beans... log.debug("Not adding bean '" + name + "' to TaskResponse because it is abstract."); } } super.performSubtasks(req, res); }
From source file:com.easyjf.container.impl.SpringContainer.java
public Collection getBeansName() { if (factory instanceof ApplicationContext) { ApplicationContext context = (ApplicationContext) factory; return Arrays.asList(context.getBeanDefinitionNames()); }//from www .ja v a2 s . c o m return null; }
From source file:com.fortuityframework.spring.broker.SpringEventListenerLocator.java
/** * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent) *///from w ww . j av a 2 s . co m @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextStartedEvent || event instanceof ContextRefreshedEvent) { ApplicationContext context = ((ApplicationContextEvent) event).getApplicationContext(); for (String beanDefinitionName : context.getBeanDefinitionNames()) { Class<?> type = context.getType(beanDefinitionName); if (type != null && type.getMethods() != null) { for (Method m : type.getMethods()) { registerMethodAsListener(context, beanDefinitionName, m); } } } } }
From source file:com.meals.on.wheels.MealsOnWheelsApplication.java
@Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) { return args -> { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { LOGGER.debug(beanName);// w w w .j a v a2 s . com } } }; }
From source file:kzht.gm.springframework.extension.context.PrototypeBeanInitializeListener.java
private void initializeAspectJWorld(ApplicationContext ctx) { if (ctx == null) { return;//from w w w. j a va 2s . c om } if (LazyBeanDocumentReader.loadLazyInitAttr()) { return; } for (String name : ctx.getBeanDefinitionNames()) { if (ctx.isPrototype(name)) { try { // AspectJExpression ??? AspectJ ???? ctx.getBean(name); } catch (BeansException e) { // ApplicationContext ???????????????? // Prototype() ? Prototype() ?????????? // ? ApplicationContext ?????????????????? // ?????????? } } } }
From source file:com.benfante.minimark.controllers.AdminController.java
@RequestMapping public String spring(HttpServletRequest req, HttpServletResponse res, Model model) { ApplicationContext ctx = this.ctx; List<String> beans = new LinkedList<String>(); while (ctx != null) { String[] beanNames = ctx.getBeanDefinitionNames(); for (String beanName : beanNames) { Object bean = null;/* ww w . j a v a 2s . c o m*/ try { bean = ctx.getBean(beanName); beans.add(beanName + " (" + bean.getClass() + ") [" + ctx.getDisplayName() + "]"); } catch (BeansException beansException) { beans.add(beanName + " (only definition) [" + ctx.getDisplayName() + "]"); } } ctx = ctx.getParent(); } Collections.sort(beans); model.addAttribute("beans", beans); return "admin/spring"; }
From source file:flex.contrib.services.SpringAutowiringBootstrapService.java
@Override public void initialize(String id, ConfigMap properties) { MessageBroker mb = getMessageBroker(); // get the application context ServletContext servletContext = mb.getInitServletContext(); ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); // loop over all registered bean definitions String[] beanNames = ctx.getBeanDefinitionNames(); for (int i = 0; i < beanNames.length; i++) { String beanName = beanNames[i]; try {/* w ww . ja va 2s . c o m*/ Object bean = ctx.getBean(beanName); // if the bean is a remoting destination bean, create the remoting destination if (FlexUtils.hasRemotingDestinationAnnotation(bean)) { FlexUtils.createRemotingDestination(bean, beanName, mb); } } catch (BeanIsAbstractException e) { // do nothing... abstract beans aren't going to be remote destination beans } catch (ConfigurationException e) { log.error("Unable to configure remoting destination for Spring service named '" + beanName + "'.", e); } catch (RuntimeException e) { log.error("Unable to create remoting destination for Spring service named '" + beanName + "'.", e); } } }
From source file:org.cometd.oort.spring.OortSpringAnnotationTest.java
@Test public void testSpringWiringOfOort() throws Exception { Server server = new Server(); ServletContextHandler context = new ServletContextHandler(server, "/"); WebSocketServerContainerInitializer.configureContext(context); context.addEventListener(new ContextLoaderListener()); context.getInitParams().put(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext.xml"); server.start();//from w w w. j a va 2s . c o m ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(context.getServletContext()); String beanName = Introspector.decapitalize(OortService.class.getSimpleName()); String[] beanNames = applicationContext.getBeanDefinitionNames(); assertTrue(Arrays.asList(beanNames).contains(beanName)); OortService service = (OortService) applicationContext.getBean(beanName); assertNotNull(service); Seti seti = service.seti; assertNotNull(seti); Oort oort = seti.getOort(); assertNotNull(oort); BayeuxServer bayeux = oort.getBayeuxServer(); assertNotNull(bayeux); SecurityPolicy policy = bayeux.getSecurityPolicy(); assertNotNull(policy); assertTrue(policy instanceof OortSecurityPolicy); server.stop(); }