Shikarn-O
Shikarn-O

Reputation: 3417

How to create Aspect for mapper classes generated by mybatis framework?

I want to create aspect for profiling db calls using mybatis with this pointcut

@Pointcut("execution(public * org.example.mybatisgenerated.*Mapper+.*(..) )")
public void anyGeneratedMapperMethod(){}

Problem is that mappers are interfaces and there are no concrete classes, like this.

public interface SampleMapper {

  int deleteByPrimaryKey(String sampleGuid);

  int insert(Sample record);
}

Implementation of mapper(actual sql scripts) are in xml files. Concrete classes are created as proxies. Is it possible to somehow advice all methods of mappers?

Aspectj load-time weaving is used. May be this is possible with some another kind of weaving. I do not want to wrap all mappers with concrete implementation, it will be a lot of useless classes.

Upvotes: 2

Views: 2316

Answers (1)

cporte
cporte

Reputation: 2191

There is an interceptor build-in feature in MyBatis. Maybe you can use it ?

Upvotes: 2

Related Questions