0

I have a Spring(boot) application that I want to convert to Quarkus, or at least to microprofile. The vast majority of the code is framework agnostic: It has no Spring dependencies, not even Spring related annotations. Only one subproject depends on Spring(boot). It holds a few (rest)controllers and integrates the pure Java pieces into an application with Spring Java config. The idea was to use Spring for what it is good at: application integration, and not to use the framework in an invasive way. So, I thought that the migration to a different framework like microprofile would only involve the replacement of the Spring(boot) subproject with a subproject based on microprofile. And that is almost true: For every Spring construct that I use, I found a non-invasive microprofile equivalent. With one exception.

I found no working equivalent for the combination of @Bean("beanName") and @ConfigurationProperties(prefix = "configPrefix") on a Java config method that produces a bean. Is there a non-invasive way in CDI equivalent to:

@Bean( name="osmPostgisFeatureDataSource" )
@ConfigurationProperties(prefix = "postgis-data-source")
DataSource osmPostgisFeatureDataSource() {
        HikariDataSource result= new HikariDataSource();
        result.setPoolName("osmPostgisFeatureDataSource");
        return result;
}

This first guess does not work: (At least with quarkus)

@Produces @Singleton @Startup @Named("pumpkinBean")
@ConfigProperties(prefix="pumpkin") // Does not work
// Not supported on methods: @ConfigMapping(prefix="pumpkin")
Fruit pumpkinBean(@Named( "pearBean") Fruit dependency ) {
    System.out.println("De pompoen. dependency.name="+ dependency.name);
    return new Fruit();
}

Does anyone know a simple non-invasive way to configure a bean from properties without annotating the bean class? (In my case, the bean class is part of an application dependency, so annotating it would involve the creation of a subclass for that purpose only.)

0 Answers0