applicationContext-resource.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"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.2.xsd ">
  <context:component-scan base-package="com.huawei" />
</beans>

base:

public interface BaseDao<T> {}

@Component("baseDao")
public class BaseDaoImpl<T> implements BaseDao<T>{
  private Class clazz;
  public BaseDaoImpl(){
    ParameterizedType type=(ParameterizedType) this.getClass().getGenericSuperclass();
    clazz =(Class) type.getActualTypeArguments()[0];
  }
  public Class getClazz() {
    return clazz;
  }
  public void setClazz(Class clazz) {
    this.clazz = clazz;
  }
}

action:

/**
* @Controller:专门注解 控制层 类
* @Service :专门注解 业务层类
* @Repository:专门注解持久层类
* @Component:可以注解任何类
* @Scope: 控制是否单例
* @Autowired 和 @Resource 都可以注解 被注入的属性
* @author Administrator
*
*/
@Controller
@Scope("prototype")
public class UserAction {
  @Autowired
  private UserService userService;
  public void add(){
    System.out.println("======UserAction=======");
    userService.add();
  }
  public UserService getUserService() {
    return userService;
  }
  public void setUserService(UserService userService) {
    this.userService = userService;
  }
  public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-resource.xml");
    UserAction u1 =(UserAction) context.getBean("userAction");
    System.out.println("111");
    u1.add();
  }
}

service:

public interface UserService {
  public void add();
}

@Service("userService")
public class UserServiceImpl implements UserService {
  @Autowired
  private UserDao userDao;
  @Override
  public void add() {
    System.out.println("========UserServiceImpl========");
    userDao.add();
  }
  public UserDao getUserDao() {
    return userDao;
  }
  public void setUserDao(UserDao userDao) {
    this.userDao = userDao;
  }
}

dao:

public interface UserDao extends BaseDao<User>{
  public void add();
}

@Repository("userDao")
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao{
  @Override
  public void add() {
    System.out.println("=========UserDaoImpl=========");
  }
}

advice:

/*
* <bean id="logAdvice" class="com.chdsxt.advice.LogAdvice" />
  <aop:config >
    <aop:pointcut expression="execution(public * com.chdsxt.service.impl.*.add*(..))" id="logCut"/>
    <aop:aspect ref="logAdvice">
      <!-- <aop:after method="addLog" pointcut-ref="logCut" />
      <aop:before method="addBefore" pointcut-ref="logCut"/>
      <aop:around method="addAround" pointcut-ref="logCut"/> -->
      <aop:after-returning method="addReturn" pointcut-ref="logCut"/>
    </aop:aspect>
  </aop:config>
**/
@Component
@Aspect
public class LogAdvice {
  @Pointcut("execution(public * com.huawei.service.impl.*.add*(..))")
  private void logCut(){}
  @After("logCut()")
  public void logAfter(){
    System.out.println("做日志操作............");
  }
}

po:

public class User {}

spring AOP 注解配置的更多相关文章

  1. spring aop注解配置

    spring aop是面向切面编程,使用了动态代理的技术,这样可以使业务逻辑的代码不掺入其他乱七八糟的代码 可以在切面上实现合法性校验.权限检验.日志记录... spring aop 用的多的有两种配 ...

  2. Spring AOP—注解配置方法的使用

    Spring除了支持Schema方式配置AOP,还支持注解方式:使用@AspectJ风格的切面声明. 1 启用对@AspectJ的支持 Spring默认不支持@AspectJ风格的切面声明,为了支持需 ...

  3. Spring AOP注解配置demo

    https://blog.csdn.net/yhl_jxy/article/details/78815636#commentBox

  4. spring aop注解方式与xml方式配置

    注解方式 applicationContext.xml 加入下面配置 <!--Spring Aop 启用自动代理注解 --> <aop:aspectj-autoproxy proxy ...

  5. 基于注解的Spring AOP的配置和使用

    摘要: 基于注解的Spring AOP的配置和使用 AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不 ...

  6. Spring AOP注解为什么失效?90%Java程序员不知道

    使用Spring Aop注解的时候,如@Transactional, @Cacheable等注解一般需要在类方法第一个入口的地方加,不然不会生效. 如下面几种场景 1.Controller直接调用Se ...

  7. spring AOP为什么配置了没有效果?

     spring Aop的配置一定要配置在springmvc配置文件中         springMVC.xml 1 <!-- AOP 注解方式 :定义Aspect --> <!-- ...

  8. Spring aop注解失效

    问题 在spring 中使用 @Transactional . @Cacheable 或 自定义 AOP 注解时,对象内部方法中调用该对象的其他使用aop机制的方法会失效. @Transactiona ...

  9. JavaWeb_(Spring框架)注解配置

    系列博文 JavaWeb_(Spring框架)xml配置文件  传送门 JavaWeb_(Spring框架)注解配置 传送门 Spring注解配置 a)导包和约束:基本包.aop包+context约束 ...

随机推荐

  1. innotop监控mysql

    InnoTop 是一个系统活动报告,类似于Linux性能工具,它与Linux的top命令相仿,并参考mytop工具而设计. 它专门用后监控InnoDB性能和MySQL服务器.主要用于监控事务,死锁,外 ...

  2. SQL 实践和技巧 <2>

    转自   http://i.cnblogs.com/EditPosts.aspx?opt=1 几个小技巧   (1)||的使用: select ‘(‘||phone[1,3]||’)’phone[5, ...

  3. BASIC-28_蓝桥杯_Huffuman树

    题目: 问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, pn-1},用这列数构造Huffman树的过程如下 ...

  4. C/C++基础----函数

    用实参初始化形参时会忽略掉顶层const. 尽量使用常量引用,普通引用会限制所能接受的实参类型,也会给调用者误导. 管理数组实参的3种方法: 数组本身包含一个结束标记 传递指向数组首尾元素的指针 定义 ...

  5. red hat官方的rhel操作系统版本号与内核版本号的对应关系

    原文在如下网址:https://access.redhat.com/articles/3078 The tables below list the major and minor Red Hat En ...

  6. 关于win时间同步的解决方案

    将以下的批处理执行:net stop w32time sc config w32time start= auto net start w32time w32tm /config /update /ma ...

  7. matlab批量修改图片大小

    转自:http://blog.csdn.net/cike0cop/article/details/53087995 %author:coplin %time:2016-10-10 %function: ...

  8. OpenGL chapter3 基础渲染

    3.1 基础图形管线 三种向OpenGl着色器传递渲染数据的方法:属性,Uniform和纹理.3.2 创建坐标系 3.2.1 正投影 GLFrustum::SetOrthographic(⋯⋯): 3 ...

  9. Java集合类性能分析

    [转]对于Android开发者来说深入了解Java的集合类很有必要主要是从Collection和Map接口衍生出来的,目前主要提供了List.Set和Map这三大类的集合,今天Android吧(ard ...

  10. IntelliJ IDEA神器使用技巧笔记

    1. Alt + 数字 打开idea 快捷键打开相应的窗口: 高效定位代码: 无处不在的跳转 1.项目间的跳转: Windows ->   ctrl+alt+[   /  ] 2.文件之间的跳转 ...