spring aop xml版代码_无分析

 

对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

 

 

 

 

 

posted @ 2020-10-24 15:25  圣金巫灵  阅读(92)  评论(0编辑  收藏  举报