-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getting a single extension fails when multiple extensions exist even using Primary #38
Comments
I don't know how I can help here. 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 |
Maybe this link helps. |
In GreetingsController you say:
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 |
Maybe an idea is to use the meta annotation concept from Spring (for more details see this). @Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Extension
@Component
public @interface SpringExtension {
} where It's just an idea. It's not validated in practice. |
I've got a more representative demo Spring PF4J demo here:
https://github.com/claymccoy/Pf4jSpringGreetingDemo
It works fine, even when I uncomment the single greeting endpoint.
https://github.com/claymccoy/Pf4jSpringGreetingDemo/blob/master/src/main/java/org/pf4j/demo/GreetingsController.java#L25
But with the single greeting endpoint uncommented, if I add more greeting extensions via plugins it fails. That is not surprising. However, I would expect it to work if one of the extensions is marked with the Primary Spring annotation. But I still get this:
The text was updated successfully, but these errors were encountered: