zoukankan      html  css  js  c++  java
  • BeanFactory 与 FactoryBean

    BeanFactory:

      1.一个工厂,负责生产和管理bean。

      2.IOC容器的核心接口,负责实例化、定位、配置应用程序中的对象及建立这些对象的依赖。

      3.多种实现:如 DefaultListableBeanFactory、XmlBeanFactory、ApplicationContext等,其中XmlBeanFactory以XML方式描述组成应用的对象及对象间的依赖关系。

     FactoryBean

      1.FactoryBean是一个接口,当IOC容器中的Bean实现了FactoryBean如ProxyFactoryBean后,通过getBean(String BeanName)获取到的Bean对象并不是FactoryBean的实现类对象,而是这个实现类中的getObject()方法返回的对象。要想获取FactoryBean的实现类,就要getBean(&BeanName),在BeanName之前加上&。

    /**
     * @Title: BatchMethodAspect
     * @Description: 切面处理接口
     */
    public interface BatchMethodAspect {
        /**
         * @desc 控制切面动作
         * @param point
         * @throws Throwable
         * @version 1.0
         * @return
         */
        public Object controlBatchStepByLog(ProceedingJoinPoint point) throws Throwable;
    }
    /**
     * 
     * @Title: BatchMethodAspect
     * @Description: 切面处理类
     * @Version: 1.1.0
     */
    public class BatchMethodAspectImpl implements BatchMethodAspect{
        /**
         * @desc 用途描述: 根据跑批记录表,控制跑批动作
         * @param point
         * @return
         * @throws Throwable
         */
        @Override
        public Object controlBatchStepByLog(ProceedingJoinPoint point)
                throws Throwable {
    
            Signature sig = point.getSignature();
            MethodSignature msig = (MethodSignature) sig;
            
            Object target = point.getTarget();
            Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes());
            BatchStepAnno batchStepAnno = currentMethod.getAnnotation(BatchStepAnno.class);
            System.out.println(batchStepAnno.step().getEngName() + ", " + batchStepAnno.step().getChsName() + "开始处理");
            Object retVal = point.proceed();
            System.out.println(batchStepAnno.step().getEngName() + ", " + batchStepAnno.step().getChsName() + "处理完成");
            return retVal;
        }
    }
        <bean id="batchMethodAspect" class="com.sface.aspect.impl.BatchMethodAspectImpl" />
        <bean id="batchMethodAspectFactory" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="proxyInterfaces" value="com.sface.aspect.BatchMethodAspect"/>
            <property name="targetName" value="batchMethodAspect" />
        </bean>
        <aop:config>
            <aop:aspect ref="batchMethodAspectFactory">
                <aop:pointcut id="batchMethodRuleCut" expression="@annotation(com.sface.common.BatchStepAnno)" />
                <aop:around pointcut-ref="batchMethodRuleCut" method="controlBatchStepByLog"/>
            </aop:aspect>
        </aop:config>
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface BatchStepAnno {
        BatchStep step();
    }
    public interface BatchService {
        public void stopDeal()
    }
    public class BatchServiceImpl implements BatchService {
        @Override
        @BatchStepAnno(step = BatchStep.STEP_1)
        public void stopDeal() {
                //todo
        }
    }            
  • 相关阅读:
    Flask之模型字段解析与OA建模实训
    CentOS7下部署Django项目详细操作步骤
    多线程爬虫之生产者和消费者模式
    Flask的函数视图与类视图
    经典算法题之约瑟夫环与全排列
    selenium之滑块验证码破解代码详解
    基于CentOS7的MySQL数据库主从备份
    CentOS7下部署Flask项目部署
    selenium的学习和使用
    缓冲区溢出
  • 原文地址:https://www.cnblogs.com/lyrb/p/12929269.html
Copyright © 2011-2022 走看看