这是我第一次接触AOP。我有一个带有一个方面的 spring-boot 应用程序,一个记录器。搜索我得出的结论是 @Around 方法在方法之前和之后执行(我只在一个方法中调用它),这是对的吗?在我的 @Around 方法中间,有一个joinPoint.proceed(). 如果我没记错的话,这JoinPoint是我必须用来获取调用方面的方法的信息的对象,但我无法理解进程实际上在做什么!
这是我的代码:
@Around(value = "execution(* *(..)) && @annotation(Loggable)", argNames = "ProceedingJoinPoint, Loggable")
public Object logAround(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable {
String methodArguments = loggable.printMethodArguments() ? Arrays.toString(joinPoint.getArgs()) : "[]";
long start = System.currentTimeMillis();
Object returnObject = joinPoint.proceed(); // continue on the
// intercepted method
long elapsedTime = System.currentTimeMillis() - start;
String returnValue = loggable.printReturn() && returnObject != null ? returnObject.toString() : "[]";
LOG.info("Logging method: {}.{} Method arguments: {}. Method …Run Code Online (Sandbox Code Playgroud) 我有许多带有自己的哈希图的服务,我的哈希图是不可变的,它们在初始化块中进行初始化。因此,所有线程都将读取哈希图,但不会对其进行写入。
我的服务是Spring的组件,所以它们是“Spring Singletons”。
使用HashMap来做这件事有什么问题吗?我应该使用其他课程吗?为什么?
这是我正在谈论的内容的一个例子:
@Service
public class TrackingServiceOne extends TrackingService {
Map<Integer, String> mapCreditos = new HashMap<Integer, String>();
Map<Integer, String> mapDeudas = new HashMap<Integer, String>();
Map<Integer, String> mapEjemplo = new HashMap<Integer, String>();
{
mapCreditos.put(1, "hi");
mapCreditos.put(2, "example");
// And like this I will populate each map.
}
// My methods will read the maps, never write them.
}
Run Code Online (Sandbox Code Playgroud)