-
Notifications
You must be signed in to change notification settings - Fork 104
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
Problems with Extension and Scopes #4
Comments
I don't use Spring in my projects so I don't use this PF4J's extension (pf4j-spring). Make sense for you? |
You mean something like this? protected void registerExtension(Object extension, BeanDefinitionRegistry beanDefinitionRegistry) {
BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(extension.getClass())
.setScope(extension.getClass().getAnnotation(SomeSpringScopeAnnotation.class).value()) // here make use of the new added annotation e.g. @springscope
.addPropertyReference("propertyName", extension.getClass().getName())
.addPropertyValue("propertyValue", extension);
beanDefinitionRegistry.registerBeanDefinition(extension.getClass().getName(), definitionBuilder.getBeanDefinition());
} There I have edit the @PostConstruct
public void injectExtensions(BeanDefinitionRegistry beanDefinitionRegistry) {
...
} |
Yes. Something like this. |
What it's not clear for me is the comment from 1139d13#comments that says that
Can you validate this affirmation. Did you able to run the demo without problem? The modification with Thanks! |
I see that exists |
I can get it running, but not fully. The application context of the plugin is not resolved anymore. But with my fix, the scope will be set right. protected void registerExtension(Object extension, BeanDefinitionRegistry beanDefinitionRegistry) {
BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(extension.getClass())
.addPropertyReference("propertyName", extension.getClass().getName())
.addPropertyValue("propertyValue", extension);
if (extension.getClass().isAnnotationPresent(ExtensionSpringScope.class)) {
String scope = extension.getClass().getAnnotation(ExtensionSpringScope.class).value();
log.info("Registering {} with scope: {}", extension.getClass().getName(), scope);
definitionBuilder.setScope(scope);
}
beanDefinitionRegistry.registerBeanDefinition(extension.getClass().getName(), definitionBuilder.getBeanDefinition());
} What I had to change was the @Autowired
private ApplicationContext applicationContext;
public ExtensionsInjector(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
@PostConstruct
public void injectExtensions() {
BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory();
...} The post construct method don't allow parameters anymore. I don't checked if this has a relation to my changes. But now I don't get my beans from the plugin loaded... Can you check it? |
Can you fork the project (via GitHub), add your modifications to pippo-spring and give me the link? |
Yes, I can! Here: https://github.com/loefflefarn/pf4j-spring/tree/pippo-spring |
@loefflefarn |
Nice, okay. I will check it tomorow in my application and will give you feedback! Thanks a lot for you help. |
The scopes are now setted right but they cannot resolve there beans from the plugin. You can test it, if you set the scope to |
@loefflefarn |
Ah, yes. Okay, I will look around for a possible solution to help you with it. I've tested around with this, but nothing has work fine. |
Hey,
I want to extend an class that needs a other scope then the singleton. How can I specify the bean scope for the
@Extension
annotated class?I want to use your library with Spring and Vaadin 8. All works fine! But now I want to test to get
SpringView
annotated classes loaded out of the plugin. And there I have problems with the scopes of the bean that will be created by your library. TheSpringView
cannot be a singleton.Is there any option to set the singleton explicitly?
Greetings!
The text was updated successfully, but these errors were encountered: