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. SiteMap Editor for Microsoft Dynamics CRM 2011 使用说明

    How to connect to CRM environments using this tool If you already connected to a CRM deployment usin ...

  2. linux上通过lighttpd上跑一个C语言的CGI小页面以及所遇到的坑

    Common Gateway Interface如雷贯耳,遗憾的是一直以来都没玩过CGI,今天尝试一把.Tomcat可以是玩CGI的,但得改下配置.为了方便,直接使用一款更轻量级的web服务器ligh ...

  3. Maven 私服 Nexus 权限控制

    Nexus 用户 Nexus 预定义了三个用户,这三个用户对应了三个权限级别: admin:该用户拥有对Nexus服务的完全控制,默认密码为 admin123,以下为admin用户的角色树 deplo ...

  4. 【android】adb常用命令

    ADB常用命令: [adb help]获取帮助 [adb get-serialno]获取设备串号 [adb -s <serialNumber> <command>]给特定设备发 ...

  5. PHP $_SERVER 祥细解读(有事例)

    为了看的更明白,添加上了事例 例如  'www.ceshiyuming.com/ceshi.php?p=123';Array(    [HOSTNAME] =>     [PATH] => ...

  6. fiddler抓包HTTPS请求

    fiddler抓包HTTPS请求 标签: fiddlerhttps抓包 2016-03-29 21:24 23293人阅读 评论(2) 收藏 举报  分类: 不登高山不知天之高也(1)  版权声明:本 ...

  7. Java堆外内存之三:堆外内存回收方法

    一.JVM内存的分配及垃圾回收 对于JVM的内存规则,应该是老生常谈的东西了,这里我就简单的说下: 新生代:一般来说新创建的对象都分配在这里. 年老代:经过几次垃圾回收,新生代的对象就会放在年老代里面 ...

  8. js中,object可以调用style对象,[]不可以调用style对象

    <!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" Content=&q ...

  9. 9-16Jenkins-3可用的环境变量、参数化构建和依赖

    1.环境变量 可以查看可用的环境量 执行构建 2.参数化构建 3.依赖 多个工程可以在按既定顺序执行 test1225-2的构建触发器设置

  10. javascript中setInterval制作跑马灯的效果

    html代码: javascript代码 <script type="text/javascript"> function scroll() { var title = ...