码迷,mamicode.com
首页 > 其他好文 > 详细

通知advice

时间:2019-12-22 16:49:46      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:rri   als   import   log   配置文件   建议   java   nts   rda   

 

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>

通知advice

标签:rri   als   import   log   配置文件   建议   java   nts   rda   

原文地址:https://www.cnblogs.com/yunhemeihe/p/12079935.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!