Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject beans in QuarkusTestResourceLifecycleManager implementations

Tags:

cdi

quarkus

I try to implement a QuarkusTestResourceLifecycleManager implemenation which injects/looks up a bean in ArC, however the bean is not found.

public class FlywayTestResource implements QuarkusTestResourceLifecycleManager {


    @Override
    public Map<String, String> start() {

        Flyway flyway = Arc.container().instance(Flyway.class).get(); //fails
...

Is it basically possible to get some beans injected or can it not work because at this point quarkus arc is not initialized?

Update:

Looks like ConfigProvider.getConfig() does not include application.properties in its sources

enter image description here

Update2: dirty hack could be copying over application.properties to system properties which is super ugly IMO. Or is there a less cumbersome way to add application.properties to config sources?

public void loadApplicationProperties() {
        Properties properties = new Properties();

        String path = this.getClass().getClassLoader().getResource("application.properties").getPath();

        try (FileInputStream input = new FileInputStream(path)) {
            properties.load(input);

            for (String key : properties.stringPropertyNames()) {
                String value = properties.getProperty(key);
                System.setProperty(key, value);
            }

            System.out.println("Properties copied to environment variables successfully.");
        } catch (IOException e) {
           
        }
    }
like image 844
syr Avatar asked Jan 24 '26 12:01

syr


1 Answers

Starting services before the Quarkus application starts so I suppose CDI context is not still active. This extension written by @radcortez is using plain flyway to achive the result; give it a look.

like image 191
Luca Basso Ricci Avatar answered Jan 26 '26 18:01

Luca Basso Ricci