Private method interceptor method

Here is the question: I have a method digest(byte[] data). It must be closed, because we really do not need it outside the class, however I will not die if I make it public, if it helps.
The question is, can I somehow connect an interceptor to it? The fact is that it is not called as getBean('MyBean').digest(), it is called through getBean('MyBean').sign(data), where the sign has the form smth, as

public byte[] sign(byte[] data){
   ...
   b = digest(data);
   ...
   return signature;
}

thank.

+5
source share
4 answers

Even if this method is publicly available, Spring cannot intercept method calls that are made from an object containing this method. For this you will need to use AspectJ.

+3

AspectJ voodoo, public. digest() bean public, , , , - .

, , .

+1

, , - Digester digest():

public interface Digester {
  public Foo digest(byte[] data);
}

class DigesterImpl implements Digester {
  public Foo digest(byte[] data) {...}
}

spring DigesterImpl :

private final Digester digester;

MyClass(Digester digester) {
  this.digester = digester;
}

public byte[] sign(byte[] data){
   ...
   b = digester.digest(data);
   ...
   return signature;
}
0

, , , Aspect -, - () .

, , , , , Digest (Data), , .

. , , , , . :

public byte[] sign(byte[] data){
   ...
   b = (Digester)AopContext.currentProxy()).Digest(Data);
   ...
   return signature;
}

This completely binds your code with Spring AOP, and it makes the class itself aware that it is used in the context of the AOP that flies before the AOP.

0
source

All Articles