-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Labels
type: bugSomething isn't workingSomething isn't working
Description
Expected Behavior
I would like to replace the default datasource factory by a custom one. It seems to have been possible in the past with old Micronaut versions, but this is not working anymore:
import com.amazonaws.xray.sql.TracingDataSource;
import io.micronaut.configuration.jdbc.hikari.DatasourceConfiguration;
import io.micronaut.configuration.jdbc.hikari.DatasourceFactory;
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.EachBean;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Replaces;
import javax.sql.DataSource;
@Factory
@Replaces(factory = DatasourceFactory.class)
public class XrayDataSourceFactory extends DatasourceFactory {
public XrayDataSourceFactory(ApplicationContext applicationContext) {
super(applicationContext);
}
@Override
@Context
@EachBean(DatasourceConfiguration.class)
public DataSource dataSource(DatasourceConfiguration datasourceConfiguration) {
return new TracingDataSource(super.dataSource(datasourceConfiguration));
}
}Actual Behaviour
The original factory is still invoked, and the custom one ignored. This issue has been reported here: micronaut-projects/micronaut-core#4054 but the issue has been closed. I commented there but in case it is missed I am reopening a new issue.
Using delegation is a possible workaround in my specific case, but not clean due to methods visibility issues. It also took me a lot of time to understand why it was not working.
Steps To Reproduce
No response
Environment Information
No response
Example Application
No response
Version
4.9.1
Metadata
Metadata
Assignees
Labels
type: bugSomething isn't workingSomething isn't working