user7294900:
私は、トリガ春の方法に特定の種類をマップしたいです
例えば、私は機能が春のサービスメソッドを呼び出します、キーによって機能的インタフェースの地図を保存し、私はそれが静的でなければならないという問題があります。
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)
私は、静的メソッドを呼び出すために静的のSpring Beanをロードする必要があります。
private static final MySpringService mySpringService = ApplicationInitializer.getAppContext().getBean(MySpringService.class);
やSpring Beanを初期化する静的ずにそこに良いですか?
ザビエルGourmandin:
私は、Springの使用したいInitializingBean
あなたの地図が定義されているビーンのインターフェイスを。次に@Autowire
、あなたのMySpringService
あなたの豆インチ
最後に、中afterPropertiesSet()
の方法、あなたの地図の初期化コードを配置しますが、Autowiredを使用MySpringService
しますが、静的コンテキストからのSpring Beanを呼び出す必要はありませんので、あなたのメソッドの呼び出しを登録する代わりに。