@Bean
        @RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
        public FactoryBean<EntityManagerFactory> eventsEntityManagerFactory(
            final ConfigurableApplicationContext applicationContext,
            final CasConfigurationProperties casProperties,
            @Qualifier("jpaEventVendorAdapter")
            final JpaVendorAdapter jpaEventVendorAdapter,
            @Qualifier("dataSourceEvent")
            final DataSource dataSourceEvent,
            @Qualifier("jpaEventPackagesToScan")
            final BeanContainer<String> jpaEventPackagesToScan,
            @Qualifier(JpaBeanFactory.DEFAULT_BEAN_NAME)
            final JpaBeanFactory jpaBeanFactory) {
            return BeanSupplier.of(FactoryBean.class)
                .when(CONDITION.given(applicationContext.getEnvironment()))
                .supply(Unchecked.supplier(() -> {
                    val ctx = JpaConfigurationContext.builder()
                        .jpaVendorAdapter(jpaEventVendorAdapter)
                        .persistenceUnitName("jpaEventRegistryContext")
                        .dataSource(dataSourceEvent)
                        .packagesToScan(jpaEventPackagesToScan.toSet())
                        .build();
                    return jpaBeanFactory.newEntityManagerFactoryBean(ctx,
                        casProperties.getEvents().getJpa());
                }))
                .otherwiseProxy()
                .get();
        }
This is {@link CasJpaEventsAutoConfiguration}, defines certain beans via configuration
while delegating some to Spring namespaces inside the context config file.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-events-jpa/src/main/java/org/apereo/cas/config/CasJpaEventsAutoConfiguration.java