zoukankan      html  css  js  c++  java
  • 通知advice

    1.

    import com.baizhi.Annotataion.TestAnnotation;
    import com.baizhi.DAO.UserDAO;
    import com.baizhi.entity.User;
    
    /**
     * @ClassName UserServiceImpl
     * @Discription
     * @Author
     * @Date 2019/11/6 0006 10:08
     * @Version 1.0
     */
    public class UserServiceImpl implements  UserService {
    
        //交给 工厂创建 userDAO
        UserDAO userDAO;
    
        public UserDAO getUserDAO() {
            return userDAO;
        }
        public void setUserDAO(UserDAO userDAO) {
            this.userDAO = userDAO;
        }
    
        @Override
        public void register(User user) {
         /*   UserDAO userDAO = (UserDAO)FactoryUtil.getBean("userDAO");*/
            System.out.println("--------UserService    register  -----");
            //userDAO.insertUser(user);
    
        }
    
        @TestAnnotation(name = "zhangsan")
        @Override
        public boolean login(String name, String password) {
            System.out.println("-----这里是登陆-------");
            return false;
        }
    }

    2.

    import org.springframework.aop.MethodBeforeAdvice;
    
    import java.lang.reflect.Method;
    
    /**
     * @ClassName Before1
     * @Discription
     * @Author
     * @Date 2019/11/6 0006 19:24
     * @Version 1.0
     */
    public class Before1  implements MethodBeforeAdvice {
        @Override
        public void before(Method method, Object[] objects, Object o) throws Throwable {
            System.out.println("-----------------测试性能开始-----------------------");
            System.out.println(method.getName());
        }
    }

    3.spring-core.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    
       <!--
          id:当前xml配置文件中唯一,建议id的值首字母小写
          class:是要创建对象的全限定名 com.baizhi.xxx
       -->
        <bean id="userService" class="com.baizhi.service.UserServiceImpl"></bean>
        <bean id="userService1" class="com.baizhi.service.service1.UserServiceImpl"></bean>
      <!--  <bean id="user" class="com.baizhi.entity.User"></bean>-->
        <bean id="before" class="com.baizhi.advice.Before1"></bean>
        <aop:config>
            <aop:pointcut id="pc" expression="@annotation(com.baizhi.Annotataion.TestAnnotation)"></aop:pointcut>
            <aop:advisor advice-ref="before" pointcut-ref="pc"></aop:advisor>
        </aop:config>
    
    </beans>
  • 相关阅读:
    Nginx 模块开发(1)—— 一个稍稍能说明问题模块开发 Step By Step 过程
    nginx上传模块—nginx upload module-
    解决nginx上传模块nginx_upload_module传递GET参数
    nginx upload module的使用
    Nginx Upload Module 上传模块
    产品需求分析神器:KANO模型分析法
    SpringBoot @ConditionalOnBean、@ConditionalOnMissingBean注解源码分析与示例
    BAT、网易、京东等如何做大数据风控的?
    springboot 2.x 集成 drools 7.x
    Drools介绍与使用
  • 原文地址:https://www.cnblogs.com/yunhemeihe/p/12079935.html
Copyright © 2011-2022 走看看