Search code examples
quarkusmicroprofileconfigsource

Using custom config source with quarkus seems to be not working


I have a maven multi module project using quarkus. The architecturecan be simplified like this:

**module1 **-> configuration file such as application.properties

---src
------main
---------resources
------------application.properties
------------application-devlocal.properties

**module2 **-> entities + MyCustomConfigSource

---src
------main
---------java
------------MyEntity1.java
------------MyCustomConfigSource.java
---------resources
------------META-INF
---------------services
------------------org.eclipse.microprofile.config.spi.ConfigSource

**module3 **-> first quarkus module **module4 **-> second quarkus module

The goal of my custom config source is to get properties from a database table and if the property is not in the database then take it from application.properties. But when I launch the quarkus module4 in dev mode, it seems that the config source is not registered. As I have the following error:

The config property MyPropertyFromDB is required but it could not be found in any config source.

The application is able to read properties from application.properties.Moreover if I inject my MyCustomConfigSource in another bean, I am able to see all properties stored in by database (by calling the method getProperties of the config source). So it is not a connection issue.

Here is the content of my custom config source MyCustomConfigSource.

@ApplicationScope
@Transactional
public class MyCustomConfigSource implements ConfigSource
{

    @Inject
    private EntityManager entityManager;
    private Config config;

    @Override
    public int getOrdinal()
    { 
        return 500;
    }

    @Override
    public Set<String> getPropertyNames() {
       //...
    }

    @Override
    public Map<String, String> getProperties() {
        //...
    }

    @Override
    public String getValue(String key) {
        //...
    }

    @Override
    public String getName() {
        //...
    }

}

I am using quarkus 3.0.0.Alpha4 and JDK 11.

Moreover, during my tests, I see that if I add the annotation @io.quarkus.runtime.Startup then I am able to access the properties store in my database but quarkus is not able to access custom properties from application.properties anymore.


Solution

  • Unable to do it directly with microprofile but I succeed to do it with the extension quarkus-config-extensions (https://github.com/quarkiverse/quarkus-config-extensions)

    See https://github.com/quarkusio/quarkus/issues/31327