Skip to content

Replace custom DataSourceFactory with Micronaut's native unpooled datasource configuration#15

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/remove-datasource-factory
Draft

Replace custom DataSourceFactory with Micronaut's native unpooled datasource configuration#15
Copilot wants to merge 2 commits intomainfrom
copilot/remove-datasource-factory

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

Micronaut supports unpooled datasources via datasources.allow-unpooled=true configuration. The custom DataSourceFactory was reimplementing this functionality.

Changes

  • Removed DataSourceFactory.java - custom factory that manually created unpooled datasources via DriverManager.getConnection()
  • Added datasources.default.allow-unpooled=true to both main and test application.properties

The factory's driver registration (Class.forName(driver)) is handled automatically by Micronaut's datasource configuration.

Before:

@Factory
public class DataSourceFactory {
    @Singleton
    @Named("default")
    public DataSource dataSource(...) throws ClassNotFoundException {
        Class.forName(driver);
        return new DataSource() {
            @Override
            public Connection getConnection() throws SQLException {
                return DriverManager.getConnection(url, user, password);
            }
            // ... 50+ lines of boilerplate
        };
    }
}

After:

datasources.default.allow-unpooled=true
Original prompt

apparently micronaut allows unpooled connections with configuration datasources.allow-unpooled=true
Currently we have the micronaut/shopservice that relies in a com.example.shopservice.datasource.DataSourceFactory to create an unpooled datasource. I want you to remove the DataSourceFacotry and use the configuration instead to see if it works. Also update any documentation if needed.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… support

Co-authored-by: rrobetti <7221783+rrobetti@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove DataSourceFactory and use configuration for unpooled datasource Replace custom DataSourceFactory with Micronaut's native unpooled datasource configuration Dec 22, 2025
Copilot AI requested a review from rrobetti December 22, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants