public static <T> Optional<T> getBean(final ApplicationContext applicationContext, final String name, final Class<T> clazz) {
        if (applicationContext instanceof final ConfigurableApplicationContext context && !context.isActive()) {
            return Optional.empty();
        }
        return FunctionUtils.doAndHandle(() -> {
            if (applicationContext != null && applicationContext.containsBean(name)) {
                return Optional.of(applicationContext.getBean(name, clazz));
            }
            return Optional.<T>empty();
        }, e -> Optional.<T>empty()).get();
    }
Gets bean.

@param <T>                the type parameter
@param applicationContext the application context
@param name               the name
@param clazz              the clazz
@return the bean
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/spring/ApplicationContextProvider.java