@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 Map<String, Refresh> allRefresh() { Map<String, Refresh> refreshs = ctx.getBeansOfType(Refresh.class); ApplicationContext parent = ctx.getParent(); if (parent != null) { refreshs.putAll(parent.getBeansOfType(Refresh.class)); } return refreshs; }
@Override public void afterPropertiesSet() throws Exception { if (this.repositories.isEmpty()) { ApplicationContext appCtx = applicationContext; while (null != appCtx) { Map<String, CrudRepository> beans = appCtx.getBeansOfType(CrudRepository.class); setRepositories(beans.values()); appCtx = appCtx.getParent(); } } }
@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("******************************************************************************"); }
@Override public void start() { this.context = new ClassPathXmlApplicationContext(new String[] {CORE_CONFIG, PLUGIN_CONFIGS}, false); context.setId(this.id); updateLoggerFilename(); Assert.notNull(launcherContext, "no Container launcher ApplicationContext has been set"); ApplicationContext globalContext = launcherContext.getParent(); Assert.notNull(globalContext, "no global context has been set"); context.setParent(globalContext); context.registerShutdownHook(); context.refresh(); this.containerRunning = true; context.publishEvent(new ContainerStartedEvent(this)); if (logger.isInfoEnabled()) { logger.info("started container: " + context.getId()); } }
private ObjectName getObjectName( String domain, String beanKey, ApplicationContext applicationContext) throws MalformedObjectNameException { if (applicationContext.getParent() != null) { return ObjectNameManager.getInstance( String.format( "%s:type=Endpoint,name=%s,context=%s,identity=%s", domain, beanKey, ObjectUtils.getIdentityHexString(applicationContext), ObjectUtils.getIdentityHexString(applicationContext.getBean(beanKey)))); } else { return ObjectNameManager.getInstance( String.format( "%s:type=Endpoint,name=%s,identity=%s", domain, beanKey, ObjectUtils.getIdentityHexString(applicationContext.getBean(beanKey)))); } }
/** * 检查上下文中的BOP服务方法 * * @throws org.springframework.beans.BeansException */ private void registerFromContext(final ApplicationContext context) throws BeansException { if (logger.isDebugEnabled()) { logger.debug("对Spring上下文中的Bean进行扫描,查找ROP服务方法: " + context); } String[] beanNames = context.getBeanNamesForType(Object.class); for (final String beanName : beanNames) { Class<?> handlerType = context.getType(beanName); ReflectionUtils.doWithMethods( handlerType, new ReflectionUtils.MethodCallback() { public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException { ReflectionUtils.makeAccessible(method); ServiceMethod serviceMethod = method.getAnnotation(ServiceMethod.class); ServiceMethodGroup serviceMethodGroup = method.getDeclaringClass().getAnnotation(ServiceMethodGroup.class); ServiceMethodDefinition definition = null; if (serviceMethodGroup != null) { definition = buildServiceMethodDefinition(serviceMethodGroup, serviceMethod); } else { definition = buildServiceMethodDefinition(serviceMethod); } ServiceMethodHandler serviceMethodHandler = new ServiceMethodHandler(); serviceMethodHandler.setServiceMethodDefinition(definition); // 1.set handler serviceMethodHandler.setHandler(context.getBean(beanName)); // handler serviceMethodHandler.setHandlerMethod(method); // handler'method if (method.getParameterTypes().length > 0) { // handler method's parameter Class<?> aClass = method.getParameterTypes()[0]; Assert.isAssignable(RopRequest.class, aClass, "@ServiceMethod方法入参必须是RopRequest"); serviceMethodHandler.setRequestType((Class<? extends RopRequest>) aClass); } // 2.set sign fieldNames serviceMethodHandler.setIgnoreSignFieldNames( getIgnoreSignFieldNames(serviceMethodHandler.getRequestType())); addServiceMethod( serviceMethod.value(), serviceMethod.version(), serviceMethodHandler); if (logger.isDebugEnabled()) { logger.debug( "注册服务方法:" + method.getDeclaringClass().getCanonicalName() + "#" + method.getName() + "(..)"); } } }, new ReflectionUtils.MethodFilter() { public boolean matches(Method method) { return AnnotationUtils.findAnnotation(method, ServiceMethod.class) != null; } }); } if (context.getParent() != null) { registerFromContext(context.getParent()); } if (logger.isInfoEnabled()) { logger.info("共注册了" + serviceHandlerMap.size() + "个服务方法"); } }
public ApplicationContext getParent() { return applicationContext.getParent(); }
@Override public void init(ServletConfig config) throws ServletException { super.init(config); siteEmailPreferenceSetter = (SiteEmailPreferenceSetter) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.SiteEmailPreferenceSetter"); if (siteEmailPreferenceSetter == null) { throw new ServletException("Failed to set siteEmailPreferenceSetter."); } siteMembershipUpdater = (SiteMembershipUpdater) ComponentManager.getInstance().get("org.sakaiproject.lti.api.SiteMembershipUpdater"); if (siteMembershipUpdater == null) { throw new ServletException("Failed to set siteMembershipUpdater."); } siteMembershipsSynchroniser = (SiteMembershipsSynchroniser) ComponentManager.getInstance() .get("org.sakaiproject.lti.api.SiteMembershipsSynchroniser"); if (siteMembershipsSynchroniser == null) { throw new ServletException("Failed to set siteMembershipsSynchroniser."); } userFinderOrCreator = (UserFinderOrCreator) ComponentManager.getInstance().get("org.sakaiproject.lti.api.UserFinderOrCreator"); if (userFinderOrCreator == null) { throw new ServletException("Failed to set userFinderOrCreator."); } userPictureSetter = (UserPictureSetter) ComponentManager.getInstance().get("org.sakaiproject.lti.api.UserPictureSetter"); if (userPictureSetter == null) { throw new ServletException("Failed to set userPictureSettter."); } userLocaleSetter = (UserLocaleSetter) ComponentManager.getInstance().get("org.sakaiproject.lti.api.UserLocaleSetter"); if (userLocaleSetter == null) { throw new ServletException("Failed to set userLocaleSettter."); } ltiService = (LTIService) ComponentManager.getInstance().get("org.sakaiproject.lti.api.LTIService"); if (ltiService == null) { throw new ServletException("Failed to set ltiService."); } ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); // load all instance of BLTIProcessor in component mgr by type detection Collection processors = ac.getParent().getBeansOfType(BLTIProcessor.class).values(); bltiProcessors = new ArrayList(processors); // sort in using getOrder() method // sort them so the execution order is determined consistenly - by getOrder() Collections.sort( bltiProcessors, new Comparator() { public int compare(Object o1, Object o2) { return ((Comparable) ((BLTIProcessor) (o1)).getOrder()) .compareTo(((BLTIProcessor) (o2)).getOrder()); } }); }