AOP within表达式不生效

首先看Aspect的代码

@Pointcut("within(com.davidhu.shopguide.admin.mapper..*) + " || within(com.davidhu.shopguide..*.impl..*)"
" ) public void applicationPackagePointcut() { // Method is empty as this is just a Pointcut, the implementations are in the // advices. }

需要被advice执行的方法

public interface CrawlItemMapper extends BaseMapper<CrawlItem> {
    @Delete("delete from crawl_items where DATEDIFF(now(),item_create_time) > 4")
    int deleteHistoryItems();


    @Select("select id,goods_source_sn,goods_info_url,source,url_code," +
            "thumb_url,zhi_count,buzhi_count,star_count,comments_count,mall,title,emphsis,detail,detail_brief," +
            "label,category_text,item_create_time,item_update_time,main_image_url,big_image_urls,small_image_urls," +
            "price_text,price,unit_price,actual_buy_link,transfer_link,transfer_result,transfer_remark,coupon_info,taobao_pwd," +
            "score,score_minute,keywords,status,remark,creator," +
            "creator_id,last_operator,last_operator_id from crawl_items where TIMESTAMPDIFF(HOUR,item_create_time,now()) > 24")
    List<CrawlItem> getItemsAfter24Hours();

    @Select("select id, goods_source_sn,goods_info_url,source,url_code," +
            "thumb_url,zhi_count,buzhi_count,star_count,comments_count,mall,title,emphsis,detail,detail_brief," +
            "label,category_text,item_create_time,item_update_time,main_image_url,big_image_urls,small_image_urls," +
            "price_text,price,unit_price,actual_buy_link,transfer_link,transfer_result,transfer_remark,coupon_info,taobao_pwd," +
            "score,score_minute,keywords,status,remark,creator," +
            "creator_id,last_operator,last_operator_id from crawl_items_48h where TIMESTAMPDIFF(HOUR,item_create_time,now()) > 48")
    List<CrawlItem48h> getItemsAfter48Hours();

    @Select("select id, goods_source_sn,goods_info_url,url_code,thumb_url,zhi_count,buzhi_count,star_count,comments_count,mall,title,emphsis,detail,detail_brief," +
            "label,category_text,item_create_time,item_update_time,main_image_url,big_image_urls,price_text,actual_buy_link,transfer_link," +
            "taobao_pwd,transfer_result,transfer_remark,coupon_info,score,score_minute,keywords,status,remark from crawl_items where url_code=#{urlCode} for update")
    CrawlItem getItemByUrlCodeForUpdate(@Param("urlCode") String urlCode);

    @Select("select goods_info_url from crawl_items where status=1 order by score_minute desc, id desc limit 0,40")
    List<String> getFirstRecrawlItems();
}

service方法

        CrawlItem item = crawlItemMapper.getItemByUrlCodeForUpdate(code);

不知为何crawlItemMapper的方法无法触发advice,但servie方法就可以。

如果把within改成execution就没问题

    /**
     * Pointcut that matches all Spring beans in the application‘s main packages.
     */
    @Pointcut("execution(* com.davidhu.shopguide.admin.mapper.CrawlItemMapper.*(..))" )
    public void applicationPackagePointcut() {
        // Method is empty as this is just a Pointcut, the implementations are in the
        // advices.
    }

 

根据文档,对within和execution的解释是这样(https://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html)

execution(MethodPattern)Picks out each method execution join point whose signature matches MethodPattern.

within(TypePattern)Picks out each join point where the executing code is defined in a type matched by TypePattern.

看起来没有什么问题,我猜是由于mybatisplus对CrawlItemMapper的处理造成的,问题还未知。

 

AOP within表达式不生效

上一篇:树上问题基础模板


下一篇:Redis