我通过键保存功能接口映射,这些函数将调用Spring services方法,但是我有一个问题,它必须是静态的,例如:
private Map<Pair<Type,Boolean>,Function<User,Boolean>> functionInterfaces = new HashMap<>();
{
functionInterfaces .put(Pair.of(Type.MY_TYPE,Boolean.TRUE),MySpringService::myTypeMethod);
}
所以我的方法必须是静态的
public static boolean myTypeMethod(User user)
private static final MySpringService mySpringService = ApplicationInitializer.getAppContext().getBean(MySpringService.class);
还是没有静态初始化Spring Bean会更好?
最佳答案