Java Code Examples for org.springframework.aop.support.AopUtils#isAopProxy()
The following examples show how to use
org.springframework.aop.support.AopUtils#isAopProxy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskManager.java From Taroco-Scheduler with GNU General Public License v2.0 | 6 votes |
/** * 封装ScheduledMethodRunnable对象 */ private ScheduledMethodRunnable buildScheduledRunnable(Object bean, String targetMethod, String params, String extKeySuffix, String scheduleKey) { Method method; Class<?> clazz; if (AopUtils.isAopProxy(bean)) { clazz = AopProxyUtils.ultimateTargetClass(bean); } else { clazz = bean.getClass(); } if (params != null) { method = ReflectionUtils.findMethod(clazz, targetMethod, String.class); } else { method = ReflectionUtils.findMethod(clazz, targetMethod); } if (ObjectUtils.isEmpty(method)) { zkClient.getTaskGenerator().getScheduleTask().saveRunningInfo(scheduleKey, ScheduleServer.getInstance().getUuid(), "method not found"); log.error("启动动态任务失败: {}, 失败原因: {}", scheduleKey, "method not found"); return null; } return new ScheduledMethodRunnable(bean, method, params, extKeySuffix); }
Example 2
Source File: DynamicTaskManager.java From uncode-schedule with GNU General Public License v2.0 | 6 votes |
private static ScheduledMethodRunnable _buildScheduledRunnable(Object bean, String targetMethod, String params) throws Exception { Assert.notNull(bean, "target object must not be null"); Assert.hasLength(targetMethod, "Method name must not be empty"); Method method; ScheduledMethodRunnable scheduledMethodRunnable; Class<?> clazz; if (AopUtils.isAopProxy(bean)) { clazz = AopProxyUtils.ultimateTargetClass(bean); } else { clazz = bean.getClass(); } if (params != null) { method = ReflectionUtils.findMethod(clazz, targetMethod, String.class); } else { method = ReflectionUtils.findMethod(clazz, targetMethod); } Assert.notNull(method, "can not find method named " + targetMethod); scheduledMethodRunnable = new ScheduledMethodRunnable(bean, method, params); return scheduledMethodRunnable; }
Example 3
Source File: CommandServiceImpl.java From putnami-web-toolkit with GNU Lesser General Public License v3.0 | 5 votes |
private void scanBean(Object bean, String name) { Class<?> implClass = bean.getClass(); if (AopUtils.isAopProxy(bean)) { implClass = AopUtils.getTargetClass(bean); } Annotation serviceAnnotation = AnnotationUtils.findAnnotation(implClass, this.serviceAnnotation); if (serviceAnnotation != null) { for (Class<?> inter : implClass.getInterfaces()) { this.injectService(inter, bean); } } }
Example 4
Source File: ClassUtils.java From DataGenerator with Apache License 2.0 | 5 votes |
public static Class<?> getTargetClass(Object obj) { if (AopUtils.isAopProxy(obj)) { return AopUtils.getTargetClass(obj); } else { return (obj instanceof Class) ? (Class) obj : obj.getClass(); } }
Example 5
Source File: DelayQueueScaner.java From summerframework with Apache License 2.0 | 5 votes |
@Override protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) { try { Object beanCopy = bean; synchronized (proxyedSet) { if (proxyedSet.contains(beanName)) { return beanCopy; } proxyedSet.add(beanName); Class<?> serviceInterface = this.findTargetClass(beanCopy); Method[] methods = serviceInterface.getMethods(); List<Method> annotationMethods = Lists.newArrayList(); for (Method method : methods) { Delay anno = method.getAnnotation(Delay.class); if (anno != null) { annotationMethods.add(method); } } if (!annotationMethods.isEmpty()) { interceptor = new DelayQueueInterceptor(rabbitTemplate); } else { return beanCopy; } if (!AopUtils.isAopProxy(beanCopy)) { beanCopy = super.wrapIfNecessary(beanCopy, beanName, cacheKey); } else { AdvisedSupport advised = this.getAdvisedSupport(beanCopy); Advisor[] advisor = buildAdvisors(beanName, this.getAdvicesAndAdvisorsForBean(null, null, null)); for (Advisor avr : advisor) { advised.addAdvisor(0, avr); } } return beanCopy; } } catch (Exception e) { throw new RuntimeException(e); } }
Example 6
Source File: ServiceBean.java From dubbox with Apache License 2.0 | 5 votes |
@Override protected Class getServiceClass(T ref) { if (AopUtils.isAopProxy(ref)) { return AopUtils.getTargetClass(ref); } return super.getServiceClass(ref); }
Example 7
Source File: MethodJmsListenerEndpoint.java From spring-analysis-note with MIT License | 5 votes |
@Nullable public Method getMostSpecificMethod() { if (this.mostSpecificMethod != null) { return this.mostSpecificMethod; } Method method = getMethod(); if (method != null) { Object bean = getBean(); if (AopUtils.isAopProxy(bean)) { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean); method = AopUtils.getMostSpecificMethod(method, targetClass); } } return method; }
Example 8
Source File: DtsTransactionScaner.java From dts with Apache License 2.0 | 5 votes |
private Class<?> findTargetClass(Object proxy) throws Exception { if (AopUtils.isAopProxy(proxy)) { AdvisedSupport advised = getAdvisedSupport(proxy); Object target = advised.getTargetSource().getTarget(); return findTargetClass(target); } else { return proxy.getClass(); } }
Example 9
Source File: SshdShellAutoConfiguration.java From sshd-shell-spring-boot with Apache License 2.0 | 5 votes |
private void loadSshdShellCommands(Map<String, Map<String, CommandExecutableDetails>> sshdShellCommandsMap, Object obj) { Class<?> clazz = AopUtils.isAopProxy(obj) ? AopUtils.getTargetClass(obj) : obj.getClass(); SshdShellCommand annotation = AnnotationUtils.findAnnotation(clazz, SshdShellCommand.class); Map<String, CommandExecutableDetails> map = getSupplierMap(annotation, sshdShellCommandsMap); loadSshdShellCommandSuppliers(clazz, annotation, map, obj); }
Example 10
Source File: SpringCommandFactory.java From mcspring-boot with MIT License | 5 votes |
@Override public <K> K create(Class<K> cls) throws Exception { K bean = beanFactory.getBean(cls); if (!(bean instanceof Iterable) && AopUtils.isAopProxy(bean)) { return (K) ((Advised) bean).getTargetSource().getTarget(); } return bean; }
Example 11
Source File: CommandLineDefinition.java From mcspring-boot with MIT License | 5 votes |
@SneakyThrows private Object getBean(BeanFactory factory, String name) { Object bean = factory.getBean(name); if (AopUtils.isAopProxy(bean)) { return ((Advised) bean).getTargetSource().getTarget(); } return bean; }
Example 12
Source File: ApiRequestHandlerProvider.java From swagger-more with Apache License 2.0 | 5 votes |
private BiFunction<List<HandlerMethod>, ? super ServiceBean, List<HandlerMethod>> toMappingEntries() { return (list, bean) -> { Object object = AopUtils.isAopProxy(bean.getRef()) ? AopProxyUtils.getSingletonTarget(bean.getRef()) : bean.getRef(); list.addAll(Arrays.stream(bean.getInterfaceClass().getDeclaredMethods()) .filter(method -> !Modifier.isStatic(method.getModifiers())) .filter(method -> AnnotatedElementUtils.hasAnnotation(method, ApiMethod.class)) .map(method -> new HandlerMethod(object, method)) .collect(Collectors.toList())); return list; }; }
Example 13
Source File: MethodJmsListenerEndpoint.java From spring4-understanding with Apache License 2.0 | 5 votes |
public Method getMostSpecificMethod() { if (this.mostSpecificMethod != null) { return this.mostSpecificMethod; } else if (AopUtils.isAopProxy(this.bean)) { Class<?> target = AopProxyUtils.ultimateTargetClass(this.bean); return AopUtils.getMostSpecificMethod(getMethod(), target); } else { return getMethod(); } }
Example 14
Source File: ConfigurationPropertiesDestructionRebindingHelper.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
@Override public void postProcessBeforeDestruction(Object bean, String name) throws BeansException { if (environment == null) { return; } Object target = bean; if (AopUtils.isAopProxy(bean)) { target = ProxyUtils.getTargetObject(target); } if (AnnotationUtils.findAnnotation(target.getClass(), ConfigurationProperties.class) == null) { return; } try { target.getClass().getConstructor(); } catch (NoSuchMethodException e) { logger.debug("can not found default constructor, skip it"); return; } try { ConfigurationProperties annotation = AnnotationUtils.findAnnotation( target.getClass(), ConfigurationProperties.class); String prefix = annotation.prefix(); Object result = Binder.get(environment).bind(prefix, (Class) target.getClass()).orElseCreate(target.getClass()); BeanUtils.copyProperties(result, target); } catch (Throwable t) { logger.warn("error while process destruction bean with name: {}", name, t); } }
Example 15
Source File: DhisConvenienceTest.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * If the given class is advised by Spring AOP it will return the target * class, i.e. the advised class. If not the given class is returned * unchanged. * * @param object the object. */ @SuppressWarnings( "unchecked" ) private <T> T getRealObject( T object ) throws Exception { if ( AopUtils.isAopProxy( object ) ) { return (T) ((Advised) object).getTargetSource().getTarget(); } return object; }
Example 16
Source File: AopTestUtils.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Get the <em>target</em> object of the supplied {@code candidate} object. * <p>If the supplied {@code candidate} is a Spring * {@linkplain AopUtils#isAopProxy proxy}, the target of the proxy will * be returned; otherwise, the {@code candidate} will be returned * <em>as is</em>. * * @param candidate the instance to check (potentially a Spring AOP proxy); * never {@code null} * @return the target object or the {@code candidate}; never {@code null} * @throws IllegalStateException if an error occurs while unwrapping a proxy * @see Advised#getTargetSource() * @see #getUltimateTargetObject */ @SuppressWarnings("unchecked") public static <T> T getTargetObject(Object candidate) { Assert.notNull(candidate, "candidate must not be null"); try { if (AopUtils.isAopProxy(candidate) && (candidate instanceof Advised)) { return (T) ((Advised) candidate).getTargetSource().getTarget(); } } catch (Exception e) { throw new IllegalStateException("Failed to unwrap proxied object.", e); } return (T) candidate; }
Example 17
Source File: AbstractMBeanInfoAssembler.java From java-technology-stack with MIT License | 3 votes |
/** * Get the description of the MBean resource. * <p>Default implementation returns a simple description for the MBean * based on the class name. * @param managedBean the bean instance (might be an AOP proxy) * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @throws JMException in case of errors */ protected String getDescription(Object managedBean, String beanKey) throws JMException { String targetClassName = getTargetClass(managedBean).getName(); if (AopUtils.isAopProxy(managedBean)) { return "Proxy for " + targetClassName; } return targetClassName; }
Example 18
Source File: AnnotationBean.java From spring-boot-starter-dubbo with Apache License 2.0 | 3 votes |
/** * 获取bean的原始类型 * * @param bean * 输入的bean对象 * @return bean的原始类型 */ private Class<?> getOriginalClass(Object bean) { if (AopUtils.isAopProxy(bean)) { return AopUtils.getTargetClass(bean); } return bean.getClass(); }
Example 19
Source File: AbstractMBeanInfoAssembler.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Get the description of the MBean resource. * <p>Default implementation returns a simple description for the MBean * based on the class name. * @param managedBean the bean instance (might be an AOP proxy) * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @throws JMException in case of errors */ protected String getDescription(Object managedBean, String beanKey) throws JMException { String targetClassName = getTargetClass(managedBean).getName(); if (AopUtils.isAopProxy(managedBean)) { return "Proxy for " + targetClassName; } return targetClassName; }
Example 20
Source File: AbstractMBeanInfoAssembler.java From spring-analysis-note with MIT License | 3 votes |
/** * Get the description of the MBean resource. * <p>Default implementation returns a simple description for the MBean * based on the class name. * @param managedBean the bean instance (might be an AOP proxy) * @param beanKey the key associated with the MBean in the beans map * of the {@code MBeanExporter} * @throws JMException in case of errors */ protected String getDescription(Object managedBean, String beanKey) throws JMException { String targetClassName = getTargetClass(managedBean).getName(); if (AopUtils.isAopProxy(managedBean)) { return "Proxy for " + targetClassName; } return targetClassName; }