Comments (13)
I don't use Spring in my projects so I don't use this PF4J's extension (pf4j-spring).
This project is very tiny and easy to hack. All the business is available in two classes: SpringExtensionFactory
and ExtensionsInjector
.
My idea is to add a new annotation (for example @SpringScope) on class annotated with @extension. In this mode if you have the class (name) of extension you can read the value from @SpringScope.
All you need to do is to modify SpringExtensionFactory
or ExtensionsInjector
and to use the scope value when register the extension as Spring's bean.
Make sense for you?
from pf4j-spring.
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 ExtensionsInjector
. I don't tested it yet and don't know if this work, but it can be an idea for it. The biggest change would be the switch from the SingleBeanRegistry
to BeanDefinitionRegistry
.
@PostConstruct
public void injectExtensions(BeanDefinitionRegistry beanDefinitionRegistry) {
...
}
from pf4j-spring.
Yes. Something like this.
from pf4j-spring.
What it's not clear for me is the comment from 1139d13#comments that says that
PostConstruct cannot work with parameters of the method
Can you validate this affirmation. Did you able to run the demo without problem?
The modification with ExtensionsInjector.injectExtensions(SingletonBeanRegistry beanRegistry)
is an attempt to solve #3.
Thanks!
from pf4j-spring.
I see that exists org.springframework.context.annotation.Scope
. It's an idea to use this annotation.
from pf4j-spring.
org.springframework.context.annotation.Scope
would be great for this!
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 @PostConstruct
method.
@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?
from pf4j-spring.
Can you fork the project (via GitHub), add your modifications to pippo-spring and give me the link?
from pf4j-spring.
Yes, I can! Here: https://github.com/loefflefarn/pf4j-spring/tree/pippo-spring
from pf4j-spring.
@loefflefarn
I made some modifications on master to organize better the code and to prepare things for Scope implementation.
I created a new branch "scope" that contains all modifications. I added scope "prototype" on one of extension from demo and it works. I will create a PR to have the possibility to review the code and add comments.
from pf4j-spring.
Nice, okay. I will check it tomorow in my application and will give you feedback! Thanks a lot for you help.
from pf4j-spring.
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 prototype
in the demo application-plugin2
.
from pf4j-spring.
@loefflefarn
I explained yesterday in some comments of PR #6 why this problem appear.
from pf4j-spring.
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.
from pf4j-spring.
Related Issues (20)
- update dependencies to newest spring 5.+ versions HOT 1
- Concrete bean could not be received from the application context HOT 1
- SpringPlugin start/stop/start results in Exception HOT 2
- Loading plugin on-runtime : Ambiguous hander methods mapped & ConcurrentModificationException when unregistering routes
- I use it SpringPluginManager, It seems to be a single case. HOT 4
- How to update the βList<Greeting>β while some plugins unloaded and deleted? HOT 4
- How to add integration tests for the plugin?
- self contained example HOT 1
- Jpa in plug-in not working HOT 1
- Hi author, Can I send a pull request to PF4J-Spring to support the Spring parent-child context οΌ
- Injecting beans from plugin in application doesn't work HOT 2
- run exception on pf4j-spring demo
- pf4j plugin needs to refresh and detect changes automatically with spring HOT 6
- How to get this repo versions release notes? HOT 2
- Problems with Using Pf4j-Spring HOT 1
- The real implementation cannot be accessed through the api interface. HOT 2
- When 'spring-boot-devtools' is introduced in the project, the extensions are not available. HOT 2
- How do you extend with kafka HOT 1
- Retrieve Resource from Inside Plugin HOT 1
- When will plan support Spring6.x ? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pf4j-spring.