Java Code Examples for io.micronaut.context.event.BeanCreatedEvent#getBean()

The following examples show how to use io.micronaut.context.event.BeanCreatedEvent#getBean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlternativeMigrationRunner.java    From micronaut-flyway with Apache License 2.0 6 votes vote down vote up
@Override
public FlywayConfigurationProperties onCreated(BeanCreatedEvent<FlywayConfigurationProperties> event) {
    FlywayConfigurationProperties config = event.getBean();
    String name = config.getNameQualifier();

    if (config.isEnabled()) {
        if (config.hasAlternativeDatabaseConfiguration()) {
            DataSource dataSource = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, config.getUrl(), config.getUser(), config.getPassword());
            run(config, dataSource);
        } else {
            if (!applicationContext.containsBean(DataSource.class, Qualifiers.byName(name))) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("* Flyway bean not created for identifier [" + name + "] because no data source was found with a named qualifier of the same name.");
                }
            }
        }
    }

    return config;
}
 
Example 2
Source File: HibernateMetricsBinder.java    From micronaut-sql with Apache License 2.0 6 votes vote down vote up
@Override
public EntityManagerFactory onCreated(BeanCreatedEvent<EntityManagerFactory> event) {
    EntityManagerFactory entityManagerFactory = event.getBean();
    String sessionFactoryName = event.getBeanIdentifier().getName();
    MeterRegistry meterRegistry = meterRegistryProvider.get();
    if (entityManagerFactory instanceof SessionFactory) {

        HibernateMetrics.monitor(
                meterRegistry,
                (SessionFactory) entityManagerFactory,
                sessionFactoryName,
                tags
        );
    }

    return entityManagerFactory;
}
 
Example 3
Source File: ObjectMapperCustomizer.java    From micronaut-gcp with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectMapper onCreated(BeanCreatedEvent<ObjectMapper> event) {
    ObjectMapper objectMapper = event.getBean();
    // register modules manually
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerModule(new Jdk8Module());
    return objectMapper;
}
 
Example 4
Source File: ObjectMapperBeanEventListener.java    From micronaut-microservices-poc with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectMapper onCreated(BeanCreatedEvent<ObjectMapper> event) {
    final ObjectMapper mapper = event.getBean();
    mapper.registerModule(new JavaTimeModule());
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    return mapper;
}
 
Example 5
Source File: GormMigrationRunner.java    From micronaut-flyway with Apache License 2.0 5 votes vote down vote up
@Override
public HibernateDatastore onCreated(BeanCreatedEvent<HibernateDatastore> event) {
    HibernateDatastore hibernateDatastore = event.getBean();

    hibernateDatastore.getConnectionSources().forEach(connectionSource -> {
        String qualifier = connectionSource.getName();
        DataSource dataSource = ((HibernateConnectionSource) connectionSource).getDataSource();

        applicationContext
                .findBean(FlywayConfigurationProperties.class, Qualifiers.byName(qualifier))
                .ifPresent(flywayConfig -> run(flywayConfig, dataSource));
    });

    return hibernateDatastore;
}
 
Example 6
Source File: TransactionAwareDataSource.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource onCreated(BeanCreatedEvent<DataSource> event) {
    final BeanIdentifier beanIdentifier = event.getBeanIdentifier();
    String name = beanIdentifier.getName();
    if (name.equalsIgnoreCase("primary")) {
        name = "default";
    }
    this.qualifier = name;
    return new DataSourceProxy(event.getBean());
}
 
Example 7
Source File: PhysicalNamingStrategyConfiguration.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
@Override
public JpaConfiguration onCreated(BeanCreatedEvent<JpaConfiguration> event) {
    JpaConfiguration jpaConfiguration = event.getBean();
    jpaConfiguration.getProperties().putIfAbsent(
            AvailableSettings.PHYSICAL_NAMING_STRATEGY, physicalNamingStrategy
    );
    return jpaConfiguration;
}
 
Example 8
Source File: AbstractKafkaMetrics.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Method to add a default metric reporter if not otherwise defined.
 *
 * @param event                         The event for bean created of type AbstractKafkaConfiguration
 * @param kafkaMetricsReporterClassName The class name to use for kafka metrics registration
 * @return The bean
 */
T addKafkaMetrics(BeanCreatedEvent<T> event, String kafkaMetricsReporterClassName) {
    Properties props = event.getBean().getConfig();
    if (!props.containsKey(CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG)) {
        props.put(CommonClientConfigs.METRIC_REPORTER_CLASSES_CONFIG, kafkaMetricsReporterClassName);
        if (LOG.isDebugEnabled()) {
            LOG.debug(String.format("Adding kafka property:value of %s:%s", ProducerConfig.METRIC_REPORTER_CLASSES_CONFIG, kafkaMetricsReporterClassName));
        }
    }
    return event.getBean();
}
 
Example 9
Source File: DataSourceTransactionManagerFactory.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource onCreated(BeanCreatedEvent<DataSource> event) {
    DataSource dataSource = event.getBean();
    if (dataSource instanceof TransactionAwareDataSourceProxy) {
        return dataSource;
    } else {
        return new TransactionAwareDataSourceProxy(dataSource);
    }
}
 
Example 10
Source File: S3ClientBuilderListener.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Override
public S3ClientBuilder onCreated(BeanCreatedEvent<S3ClientBuilder> event) {
    S3ClientBuilder builder = event.getBean();
    builder.overrideConfiguration(ClientOverrideConfiguration.builder().retryPolicy(RetryMode.LEGACY).build());

    return builder;
}
 
Example 11
Source File: GoogleJacksonConfiguration.java    From micronaut-gcp with Apache License 2.0 5 votes vote down vote up
@Override
public JacksonConfiguration onCreated(BeanCreatedEvent<JacksonConfiguration> event) {
    JacksonConfiguration jacksonConfiguration = event.getBean();
    jacksonConfiguration.setModuleScan(false);
    jacksonConfiguration.setBeanIntrospectionModule(true);
    return jacksonConfiguration;
}
 
Example 12
Source File: ManagedChannelBuilderListener.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ManagedChannelBuilder<?> onCreated(BeanCreatedEvent<ManagedChannelBuilder<?>> event) {
    final ManagedChannelBuilder<?> channelBuilder = event.getBean();
    channelBuilder.maxInboundMessageSize(1024);
    return channelBuilder;
}
 
Example 13
Source File: ManagedChannelBuilderListener.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ManagedChannelBuilder<?> onCreated(BeanCreatedEvent<ManagedChannelBuilder<?>> event) {
    final ManagedChannelBuilder<?> channelBuilder = event.getBean();
    channelBuilder.maxInboundMessageSize(1024);
    return channelBuilder;
}
 
Example 14
Source File: KafkaProducerTracingInstrumentation.java    From micronaut-kafka with Apache License 2.0 4 votes vote down vote up
@Override
public Producer<?, ?> onCreated(BeanCreatedEvent<Producer<?, ?>> event) {
    final Producer<?, ?> kafkaProducer = event.getBean();
    return new TracingKafkaProducer<>(kafkaProducer, tracerProvider.get());
}
 
Example 15
Source File: KafkaConsumerTracingInstrumentation.java    From micronaut-kafka with Apache License 2.0 4 votes vote down vote up
@Override
public Consumer<?, ?> onCreated(BeanCreatedEvent<Consumer<?, ?>> event) {
    final Consumer<?, ?> consumer = event.getBean();
    return new TracingKafkaConsumer<>(consumer, tracerProvider.get());
}
 
Example 16
Source File: ServerBuilderListener.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ServerBuilder<?> onCreated(BeanCreatedEvent<ServerBuilder<?>> event) {
    final ServerBuilder<?> builder = event.getBean();
    builder.maxInboundMessageSize(1024);
    return builder;
}
 
Example 17
Source File: ManagedChannelBuilderListener.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ManagedChannelBuilder<?> onCreated(BeanCreatedEvent<ManagedChannelBuilder<?>> event) {
    final ManagedChannelBuilder<?> channelBuilder = event.getBean();
    channelBuilder.maxInboundMessageSize(1024);
    return channelBuilder;
}
 
Example 18
Source File: ServerBuilderListener.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ServerBuilder<?> onCreated(BeanCreatedEvent<ServerBuilder<?>> event) {
    final ServerBuilder<?> builder = event.getBean();
    builder.maxInboundMessageSize(1024);
    return builder;
}
 
Example 19
Source File: ServerBuilderListener.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ServerBuilder<?> onCreated(BeanCreatedEvent<ServerBuilder<?>> event) {
    final ServerBuilder<?> builder = event.getBean();
    builder.maxInboundMessageSize(1024);
    return builder;
}
 
Example 20
Source File: ServerBuilderListener.java    From micronaut-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public ServerBuilder<?> onCreated(BeanCreatedEvent<ServerBuilder<?>> event) {
    final ServerBuilder<?> builder = event.getBean();
    builder.maxInboundMessageSize(1024);
    return builder;
}