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. MySQL 中间件 mycat 的使用

    什么是MYCAT 一个彻底开源的,面向企业应用开发的大数据库集群 支持事务.ACID.可以替代MySQL的加强版数据库 一个可以视为MySQL集群的企业级数据库,用来替代昂贵的Oracle集群 一个融 ...

  2. 使用redis防止商品超发

    redis不仅仅是单纯的缓存,它还有一些特殊的功能,在一些特殊场景上很好用.redis中key的原子自增incrby和判断key不存在再写入的setnx方法,可以有效的防止超发. 下面使用两个不同的方 ...

  3. [UE4]计算机中的数据表示

    一.位:数据的最小单位,一个位仅有两种状态 一个电路,通或断:磁盘上的小磁铁,南极或北极: 使用Bit表示位,百兆带宽,一秒钟可以传输一百兆个bit 二.字节:8个位组成一个字节,一个字节有256种状 ...

  4. 3种方法轻松处理php开发中emoji表情的问题

    背景 做微信开发的时候就会发现,存储微信昵称必不可少. 可这万恶的微信支持emoji表情做昵称,这就有点蛋疼了 一般Mysql表设计时,都是用UTF8字符集的.把带有emoji的昵称字段往里面inse ...

  5. 外网访问XAMPP失败 解决方案

    xampp 访问出现New XAMPP security concept 收藏 New XAMPP security concept: Access to the requested director ...

  6. seaborn可视化特征的相关性

    import seaborn as sn sn.heatmap(trainX.corr(),vmax=1,square=True)

  7. android 系统架构简介

    Android系统采取的是分层的架构,根据官方文档提供的架构图,我们将android的系统架构分成5层,如图: 1.Application Framework (应用框架) application f ...

  8. 在 Linux 下使用mdadm创建 RAID 5

    在 RAID 5 中,数据条带化后存储在分布式奇偶校验的多个磁盘上.分布式奇偶校验的条带化意味着它将奇偶校验信息和条带化数据分布在多个磁盘上,这样会有很好的数据冗余. 在 Linux 中配置 RAID ...

  9. 内置锁(二)synchronized下的等待通知机制

    一.等待/通知机制的简介 线程之间的协作:   为了完成某个任务,线程之间需要进行协作,采取的方式:中断.互斥,以及互斥上面的线程的挂起.唤醒:如:生成者--消费者模式.或者某个动作完成,可以唤醒下一 ...

  10. VC如何得到一个文件夹的路径

    VC中没有现成的函数来选择一个文件夹,但这是经常会用到的,怎么办?自动动手,丰衣足食! 使用SHBrowseForFolder,代码如下: #include   int SelFolder(HWND ...