Skip to content

API for SpringModule that initiates a spring container itself #109

@HomeOfTheWizard

Description

@HomeOfTheWizard

I would like to use the project to help using spring based libraries in the development of maven plugins.
Maven uses a Guice based DI framework (Sisu), hence to use spring based libraries we need a bridge to inject instances from Spring into Sisu.

One way to do it is to use SpringModule.
In Sisu we can automate the creation of custom Guice modules by annotating them with JSR330 @Named.
We can then extend the SpringModule, use the constructor to pass an application context that will build the beans we need from our Spring based library, and inject them in Sisu/Guice.

@Named
public class MySpringModule extends SpringModule {

    public MySpringModule(){
        super(new AnnotationConfigApplicationContext(MySpringConfig.class));
    }
}

I think having an API that initiates the container for me would be easier and cleaner.
What would be the best is that I can directly give the spring config classes that I need from my libraries, and it does the rest.
Something similar to the following

@Named
public class MySpringModule extends SpringModule {

    public MySpringModule(){
        super( [MyLoggingLibraryConfig.class, MyAPICLientLibraryConfig.class, ... ] );
    }
}

Then SpringModule can initiate the container in its constructor and even create a binding to ApplicationContext.class in Guice in case we need it.

If you are interested into this I can gladly create a PR and contribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions