0

I want to enable AWS X-Ray for all my Repositories without annotating every controller with @XRayEnabled. Therefore I am locking for a pointcut expression.

What I got so far from the cheat sheet is that I can get all classes with the @Repository annotation with @within(org.springframework.stereotype.Repository) and all classes with a specialization of @Repository with within(@(@org.springframework.stereotype.Controller *) *).

The problem I have is that my code structure looks as follows:

@NoRepositoryBean
public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {
  // default repository from org.springframework.data.jpa.repository package
}

@NoRepositoryBean
public interface BaseRepository<T, ID> extends JpaRepository<T, ID> {
  void baseMethod() {
    ...
  }
}

@Repository
public interface Repository1 extends BaseRepository<Entity1> {
  public void method1() {
    ...
  }
}

@MyRepository // specialization of the @Repository annotation
public interface Repository2 extends BaseRepository<Entity2> {
  public void method2() {
    ...
  }
}

As you can see I am having a multilevel inheritance here. If I combine the two pointcuts mentioned above with ||, it works for method1() and method2(), but baseMethod() or all methods of the JpaRepository are ignored. Of course I could do the same with the @NoRepositoryBean annotation, but that is not good practice, as I want to do something similar with @Service annotations which have base classes without annotations.

If I add the @XRayEnabled annotation to Repository1 or Repository2, it also works and the calls are visible in X-Ray, but again bad practice.

So I would really appreciate if someone could help me to find a good solution for my problem.

Martin
  • 1
  • 1
  • Hello @cliff2310. I read all the articles before posting the question, so could you may explain how my question could be improved or what exactly is not clear about it? – Martin Jul 07 '22 at 08:19
  • This is general information that you should keep in mind, when asking questions – cliff2310 Jul 07 '22 at 15:24
  • If you read what a minimal, reproducible example is, why are you asking how to improve the question? Your question contains incomplete code, which is why nobody can reproduce your problem. Just edit the question to contain complete code and configuration. How can anyone say anything intelligent about an aspect you never posted here? Two isolated pointcuts mean that anyone willing to help first needs to recreate your situation locally, adding all the stuff you left out, speculating what the missing parts might look like. Simply post a minimal project on GitHub, and you will get helpful answers. – kriegaex Jul 10 '22 at 11:24
  • I just noticed this one again. It seems to be the same topic as another question I answered [here](https://stackoverflow.com/a/72985708/1082681), because in contrast to yours it contains an [MCVE](https://stackoverflow.com/help/mcve). Maybe you are lucky and your use case is really the same. Please let me know. Otherwise, either add a full sample project or delete the question altogether, if you do not wish to improve it. – kriegaex Jul 16 '22 at 09:23

0 Answers0