Class DatasourceFactory
java.lang.Object
io.micronaut.jdbc.BaseDatasourceFactory
io.micronaut.configuration.jdbc.hikari.DatasourceFactory
- All Implemented Interfaces:
io.micronaut.context.event.ApplicationEventListener<io.micronaut.runtime.context.scope.refresh.RefreshEvent>
,io.micronaut.core.order.Ordered
,io.micronaut.runtime.context.scope.refresh.RefreshEventListener
,AutoCloseable
,EventListener
Creates a Hikari data source for each configuration bean.
- Since:
- 1.0
- Author:
- James Kleeh, Christian Oestreich
-
Nested Class Summary
Nested classes/interfaces inherited from class io.micronaut.jdbc.BaseDatasourceFactory
BaseDatasourceFactory.DataSourceCredentials
-
Field Summary
Fields inherited from class io.micronaut.jdbc.BaseDatasourceFactory
applicationContext
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Fields inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
DEFAULT_POSITION
-
Constructor Summary
ConstructorsConstructorDescriptionDatasourceFactory
(io.micronaut.context.ApplicationContext applicationContext) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
dataSource
(DatasourceConfiguration datasourceConfiguration) Method to wire up all the HikariCP connections based on theDatasourceConfiguration
.protected void
dataSourceCredentialsChanged
(String dataSourceName, BaseDatasourceFactory.DataSourceCredentials dataSourceCredentials) Called when the datasource credentials have changed.Methods inherited from class io.micronaut.jdbc.BaseDatasourceFactory
getObservedConfigurationPrefixes, onApplicationEvent
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.runtime.context.scope.refresh.RefreshEventListener
getOrder, supports
-
Constructor Details
-
DatasourceFactory
public DatasourceFactory(io.micronaut.context.ApplicationContext applicationContext) Default constructor.- Parameters:
applicationContext
- The application context
-
-
Method Details
-
dataSource
@Context @EachBean(DatasourceConfiguration.class) @Requires(condition=JdbcDataSourceEnabled.class) public DataSource dataSource(DatasourceConfiguration datasourceConfiguration) Method to wire up all the HikariCP connections based on theDatasourceConfiguration
. If aMeterRegistry
bean exists then the registry will be added to the datasource.- Parameters:
datasourceConfiguration
- ADatasourceConfiguration
- Returns:
- A
HikariUrlDataSource
-
dataSourceCredentialsChanged
protected void dataSourceCredentialsChanged(String dataSourceName, BaseDatasourceFactory.DataSourceCredentials dataSourceCredentials) Description copied from class:BaseDatasourceFactory
Called when the datasource credentials have changed.Subclasses must implement this method to handle the updated credentials.
- Specified by:
dataSourceCredentialsChanged
in classBaseDatasourceFactory
- Parameters:
dataSourceName
- the name of the datasourcedataSourceCredentials
- the updated datasource credentials
-
close
@PreDestroy public void close()- Specified by:
close
in interfaceAutoCloseable
-