Giter VIP home page Giter VIP logo

Comments (4)

decebals avatar decebals commented on August 16, 2024

I don't know how I can help here.
The pf4j-spring is very tiny and easy to hack. All the business is available in two classes: SpringExtensionFactory and ExtensionsInjector. The extension is injected as bean in SpringExtensionFactory#create.

I am not familiar with @primary annotation but it seems that the behavior of this annotation can be easy emulated via code:

Greeting getGreeting() {
    // pseudo code
    if (greetings.isEmpty) {
        return null;
    } else {
        return greetings.get(0); // first
    }
}

If you want something automatically (not the first greeting extension), I think that you can add @primary on an extension class and use this information in ExtensionsInjector. Please take a look on #6 to have an idea.

from pf4j-spring.

decebals avatar decebals commented on August 16, 2024

Maybe this link helps.

from pf4j-spring.

decebals avatar decebals commented on August 16, 2024

In GreetingsController you say:

This works with just the system extension, but fails with more than one even when one is marked @Primary

Yes, this behavior is normal (with current implementation) because PF4J creates the extensions instances, and not Spring. In this context, any Spring's annotation that exists on the extension class (like Scope, Primary, ...) must be treated/interpreted by PF4J (pf4j-spring) when an extension's instance is created. After the extension's instance was created, the object is injected in Spring as bean.
If the extension's instance was created by Spring, then Spring would take care of all these aspects (annotations). So, the perfect/ideal solution is to let Spring to create these instances of extensions but I don't know how we can do this.

from pf4j-spring.

decebals avatar decebals commented on August 16, 2024

Maybe an idea is to use the meta annotation concept from Spring (for more details see this).
On the master branch of PF4J there is already support for the extensively decorated annotation(pf4j/pf4j#347). So, right now, we can write something like:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Extension
@Component
public @interface SpringExtension {
}

where @Extension defines an extension in PF4J and @Component defines a component in Spring.
What else we should do is implement an ExtensionFactory (see SpringExtensionFactory) that extracts the extension instance from Spring on create(Class<T> extensionClass).

It's just an idea. It's not validated in practice.

from pf4j-spring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.