@Override public void startUp() throws Exception { HSFEasyStarter.startFromPath("d:/hsf"); server = new ClassPathXmlApplicationContext("app-server.xml"); client = new ClassPathXmlApplicationContext("app-client.xml"); p(server.getBeanDefinitionNames()); p(client.getBeanDefinitionNames()); p("start"); }
@SuppressWarnings("unchecked") protected void peek() { ServletContext application = getActionServlet().getServletContext(); HttpSession session = getSession(); ApplicationContext wac = (ApplicationContext) application.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); logger.debug(wac); ApplicationContext parent = wac.getParent(); if (parent != null) logger.debug(parent.toString()); for (String n : wac.getBeanDefinitionNames()) { logger.debug(n); } // notice the dot . in the key name! wac = (ApplicationContext) application.getAttribute("org.springframework.web.struts.ContextLoaderPlugIn.CONTEXT."); if (wac != null) { logger.debug("struts ContextLoaderPlugIn context"); for (String n : wac.getBeanDefinitionNames()) { logger.debug(n); } } else { logger.debug("ContextLoaderPlugIn ac is null"); } parent = wac.getParent(); if (parent != null) { logger.debug("Parent = " + parent.toString()); } logger.debug("Servlet context"); for (Enumeration e = application.getAttributeNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String s = String.format("%s=%s", key, application.getAttribute(key)); logger.debug(s); } logger.debug("Session"); for (Enumeration e = session.getAttributeNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String s = String.format("%s=%s", key, session.getAttribute(key)); logger.debug(s); } logger.debug("request attributes:"); HttpServletRequest request = getRequest(); for (Enumeration e = request.getAttributeNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String s = String.format("%s=%s", key, request.getAttribute(key)); logger.debug(s); } }
private void initWildcardDefinitionMap() { if (null != appContexts) { for (ApplicationContext appContext : appContexts) { for (String n : appContext.getBeanDefinitionNames()) { if (isWildcardBeanName(n)) { AutowireCapableBeanFactory bf = appContext.getAutowireCapableBeanFactory(); BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) bf; BeanDefinition bd = bdr.getBeanDefinition(n); String className = bd.getBeanClassName(); if (null != className) { String orig = n; if (n.charAt(0) == '*') { // old wildcard n = "." + n.replaceAll("\\.", "\\."); } try { Matcher matcher = Pattern.compile(n).matcher(""); List<MatcherHolder> m = wildCardBeanDefinitions.get(className); if (m == null) { m = new ArrayList<MatcherHolder>(); wildCardBeanDefinitions.put(className, m); } MatcherHolder holder = new MatcherHolder(orig, matcher); m.add(holder); } catch (PatternSyntaxException npe) { // not a valid patter, we'll ignore } } else { LOG.warn("Wildcars with not class {}", n); } } } } } }
void start() { String configLocation = "spring/dubbo-provider.xml"; ApplicationContext context = new ClassPathXmlApplicationContext(configLocation); String[] names = context.getBeanDefinitionNames(); System.out.print("Beans:"); for (String string : names) System.out.print(string + ","); System.out.println(); }
public static void main(String[] args) throws Exception { ApplicationContext ctx = SpringApplication.run(Application.class, args); String[] beanNames = ctx.getBeanDefinitionNames(); LOGGER.info("bean sizes is: " + beanNames.length); // Arrays.sort(beanNames); // for (String beanName : beanNames) { // logger.info(beanName); // } }
/** * Processes security annotations from bundles using {@link * #postProcessAfterInitialization(Object, String)} method * * @param applicationContext bundle context used to look for annotations */ public void processAnnotations(ApplicationContext applicationContext) { LOGGER.info("Searching for security annotations in: {}", applicationContext.getDisplayName()); currentBundleName = getBundleName(applicationContext); for (String beanName : applicationContext.getBeanDefinitionNames()) { Object bean = applicationContext.getBean(beanName); postProcessAfterInitialization(bean, beanName); } LOGGER.info("Searched for security annotations in: {}", applicationContext.getDisplayName()); }
public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); System.out.println("Beans available in this application:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } }
public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class, args); System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } }
public Serializable execute() throws GridException { GridNode gridNode = GridFactory.getGrid().getLocalNode(); Serializable attribute = gridNode.getAttribute(""); System.out.println(nameOfPersonToSalute + ":" + (null == context)); for (String beanName : context.getBeanDefinitionNames()) { System.out.println(beanName); } return null; }
@RequestMapping(method = RequestMethod.GET) public ResponseEntity beans() { ObjectNode payload = JsonNodeFactory.instance.objectNode(); String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames(); for (int index = 0; index < beanDefinitionNames.length; index++) { String beanDefinitionName = beanDefinitionNames[index]; payload.put("" + index, beanDefinitionName); } return new ResponseEntity(payload, HttpStatus.OK); }
public static void main(String[] args) throws Exception { log.info("application start..."); ApplicationContext ctx = SpringApplication.run(ApplicationConfig.class, args); String[] defName = ctx.getBeanDefinitionNames(); for (String name : defName) { log.info("beanDefinitionName={}", name); } Busboy busboy = ctx.getBean(Busboy.class); busboy.test(); SpringApplication.exit(ctx); }
public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(StormpathAutoConfigurationApplication.class, args); log.info("Beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { log.info(beanName); } }
@Test public void logBeansInContext() { DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory; if (factory != null) { logger.debug("Bean Factory: '{}'", factory); } if (applicationContext.getParent() != null) { logger.debug("Bean Factory: '{}'", applicationContext.getParentBeanFactory()); } logger.debug("******************************************************************************"); String[] beans = applicationContext.getBeanDefinitionNames(); for (String o : beans) { logger.debug("________________________"); logger.debug("BEAN id: '{}'", o); logger.debug("\tType: '{}'", applicationContext.getType(o)); String[] aliases = applicationContext.getAliases(o); if (factory.isFactoryBean(o)) logger.debug("\tFACTORY"); if (aliases != null && aliases.length > 0) { for (String a : aliases) { logger.debug("\tAliased as: '{}'", a); } } if (factory.getBeanDefinition(o).isAbstract()) { logger.debug("\tABSTRACT"); } else { if (applicationContext.isPrototype(o)) logger.debug("\tScope: 'Prototype'"); if (applicationContext.isSingleton(o)) logger.debug("\tScope: 'Singleton'"); Annotation[] annotations = applicationContext.getBean(o).getClass().getAnnotations(); if (annotations != null && annotations.length > 0) { logger.debug("\tAnnotations:"); for (Annotation annotation : annotations) { logger.debug("\t\t'{}'", annotation.annotationType()); } } if (!applicationContext .getBean(o) .toString() .startsWith(applicationContext.getType(o).toString() + "@")) { logger.debug("\tContents: {}", applicationContext.getBean(o).toString()); } } } logger.debug("******************************************************************************"); logger.debug("*** Number of Beans={} ***", applicationContext.getBeanDefinitionCount()); logger.debug("*** Number of Bean Post Processors={} ***", factory.getBeanPostProcessorCount()); logger.debug("******************************************************************************"); }
/** * Log the <tt>joker<tt> beans in the application context. * * @param ctx Spring application context if available - may be null. */ protected static void showBeans(ApplicationContext ctx) { if (ctx != null) { Logger logger = Logger.getGlobal(); logger.info("Let's check our beans were found by Spring Boot:"); String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { if (beanName.indexOf("oke") != -1) logger.info(beanName); } } else { Logger.getGlobal().info("Application starting."); } }
@Test public void testExecutables() throws Exception { final List<String> failures = new ArrayList<String>(); for (final String beanDefinitionName : appContext.getBeanDefinitionNames()) { final Object bean = appContext.getBean(beanDefinitionName); if (bean instanceof Executable) { final Executable executable = (Executable) bean; if (!"graph".equals(executable.getCommand()) && !(executable instanceof GraphExecutable)) { executeAndCheckForOutputFile(beanDefinitionName, executable, failures); } } } if (failures.size() > 0) { fail(failures.toString()); } }
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"beans.xml"}); // // Alternatively you can get the bean by name like this: // // Action action = (Action) context.getBean("printAction"); // Action action = context.getBean(Action.class); action.execute("Hello, world!"); System.out.println(); // this is how you get the list of all beans in a context: String[] beans = context.getBeanDefinitionNames(); for (String bean : beans) { System.out.println(String.format("%s: %s", bean, context.getType(bean))); } }
private void _registerApplicationContext(ApplicationContext applicationContext) { BundleContext bundleContext = _framework.getBundleContext(); for (String beanName : applicationContext.getBeanDefinitionNames()) { Object bean = null; try { bean = applicationContext.getBean(beanName); } catch (BeanIsAbstractException biae) { } catch (Exception e) { _log.error(e, e); } if (bean != null) { _registerService(bundleContext, beanName, bean); } } }
/** 加载bean, */ @SuppressWarnings("unchecked") private void initBeans() { String[] beanNames = applicationContext.getBeanDefinitionNames(); for (String beanName : beanNames) { if (applicationContext.getBean(beanName) instanceof Interceptor /*||applicationContext.getType(beanName).isAnnotationPresent(org.majorxie.dreamvc.annotation.Interceptor.class)==true*/) { // applicationContext.getBean(beanName, Interceptor.class); interceptorBeans.add(applicationContext.getBean(beanName)); log.info("init interceptor.."); } else if (applicationContext.getBean(beanName) instanceof Controller || applicationContext .getType(beanName) .isAnnotationPresent(org.majorxie.dreamvc.annotation.Controller.class) == true) { controllerBeans.add(applicationContext.getBean(beanName)); log.info("init controller...."); } else { otherBeans.add(applicationContext.getBean(beanName)); log.info("init others..."); } } }
public void testbeans() { ApplicationContext ctx = new ClassPathXmlApplicationContext("/WEB-INF/beans.xml"); System.out.println("We have these beans:" + ctx.getBeanDefinitionNames()); }
/** {@inheritDoc} */ @Override protected Map<String, Object> getDataMap(Context context) { final ApplicationContext factory = getApplicationContext(targetResource); Map<String, Object> map = new HashMap<String, Object>(); Object value = context.getDefaultParameter(); Map<String, String> idMap = new HashMap<String, String>(); if (value instanceof Map) { for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { Object k = entry.getKey(); Object v = entry.getValue(); if (v == null) { v = k; } idMap.put(k.toString(), v.toString()); } } else { for (String part : parseDelimitedString(value, null)) { final int pos = part.indexOf('='); if (pos < 0) { throw new PaxmlRuntimeException("No '=' sign found for id mapping from line: " + part); } idMap.put(part.substring(0, pos), part.substring(pos + 1)); } } Set<String> exclude = new HashSet<String>(parseDelimitedString(context.getConst(EXCLUDE, false), DELEMITER)); Set<String> include = new HashSet<String>(parseDelimitedString(context.getConst(INCLUDE, false), DELEMITER)); Set<String> excludeType = new HashSet<String>( parseDelimitedString(context.getConst(EXCLUDE_TYPE, false), DELEMITER)); Set<String> includeType = new HashSet<String>( parseDelimitedString(context.getConst(INCLUDE_TYPE, false), DELEMITER)); if (include.size() <= 0 && includeType.size() <= 0) { include.addAll(Arrays.asList(factory.getBeanDefinitionNames())); } for (String className : includeType) { for (String id : factory.getBeanNamesForType(ReflectUtils.loadClassStrict(className, null))) { include.add(id); } } for (String className : excludeType) { for (String id : factory.getBeanNamesForType(ReflectUtils.loadClassStrict(className, null))) { exclude.add(id); } } include.removeAll(exclude); for (String name : include) { Object bean = factory.getBean(name); if (bean != null) { String id = idMap.get(name); if (id == null) { id = name; } map.put(id, bean); } } return map; }
public static void main(String[] args) { // 创建Spring容器 ApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml"); // 获取Spring容器中的所有Bean实例的名 System.out.println("--------------" + java.util.Arrays.toString(ctx.getBeanDefinitionNames())); }
public String[] getBeanDefinitionNames() { return applicationContext.getBeanDefinitionNames(); }
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("container/example8/spring-config.xml"); System.out.println(Arrays.toString(context.getBeanDefinitionNames())); }