ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

spring aop xml版代码_无分析

2020-10-24 15:32:04  阅读:17  来源: 互联网

标签:xml getHi spring void System aop hiService public out


 

对HiService的getHi方法实验aop:

package com.springmvc.service;

import org.springframework.stereotype.Component;

@Component
public class HiService {
    public void getHi() {
        System.out.println("hiService");
    }
}

 

通知:MyAdvice:

package com.springmvc.service;

public class MyAdvice {
    public void startLog() {
        System.out.println("start log");
    }
    public void stopLog() {
        System.out.println("end log");
    }
}

 

xml:

    <bean id="myAdvice" class="com.springmvc.service.MyAdvice"></bean>

    <aop:config>
        <aop:aspect ref="myAdvice">
            <aop:before method="startLog" pointcut="execution(void com.springmvc.service.HiService.getHi())" />
            <aop:after method="stopLog" pointcut="execution(void com.springmvc.service.HiService.getHi())" />
        </aop:aspect>
    </aop:config>

 

测试类和结果:

@RestController
public class HiController {
    @Autowired
    HiService hiService;
    @RequestMapping("/hi")
    public String getHi() {
        hiService.getHi();
        return "";
    }
}

访问:http://localhost:8080/mvc/hi

 

 

 

 

 

标签:xml,getHi,spring,void,System,aop,hiService,public,out
来源: https://www.cnblogs.com/dayanjing/p/13869643.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有