Comments (16)
Hi, I am able to share some of the used source code to make the controllers work in Spring Boot. I'll get back at it. Maybe it can be used as a new sub project of the PF4J especially for Spring Boot.
from pf4j-spring.
Maybe below links can help you:
from pf4j-spring.
I already tried that, but my class annotated @controller is not working.
This is not very clear on how to implement Component with PF4J, in particular for @controller (with @RequestMapping).
If someone got a working project to show us how you did that, maybe we could do a easier way to use PF4J with Spring.
from pf4j-spring.
The idea is that PF4J loads each plugin with different Java class loader.
So, it's important to know in what Spring (application) context your controller is defined. Is defined in the plugin's application context or in the big application context?
from pf4j-spring.
I have controller in both, but the one that does not work is in the plugin, so defined in with de plugin's application context.
The thing that I'm trying to do : make my big application loads dynamically Controllers (from plugins).
from pf4j-spring.
Spring comes with an hierarchically application context concept. In your case, the beans registered via plugin's application context is not visible in the big application context and vice versa.
In my example with HelloPlugin
, I set the big application context as parent for the plugin application context. In this mode I have access from plugin to the beans defined in the big application context.
The pf4j-spring
library exports extensions as beans. After this, you can use autowire to inject extensions in a spring aware class (see https://github.com/decebals/pf4j-spring/blob/scope/demo/app/src/main/java/org/pf4j/demo/Greetings.java#L30).
I don't know what can I say about your use case.
from pf4j-spring.
Ok, I finally find a way to do that :
In API :
public interface GenericController extends ExtensionPoint {
}
In Plugin :
@Extension
@RestController
public class PluginController implements GenericController {
@GetMapping("/abc")
public Object home() {
return "OK";
}
}
No need to add applicationContext.register(PluginController.class);
in the createApplicationContext()
in the plugin.
If someone find a way to do it wihtout @Extension
... :)
Edit : I wrote this before your reply, I understand now that Extensions are injected in spring beans and using "register" does not work as I expected, thanks :)
from pf4j-spring.
I have the same requirements
from pf4j-spring.
A good introduction to the problem (Spring and modularity) you can find in A Modular Architecture with Spring Boot. In that article you can read about hierarchical application context and that a child context can access bean from the parent context but not vice versa.
You can see the @Exported
annotation from that article like something similar with @Extension
annotation from PF4J (both annotations register an object as singleton bean in the parent context).
The solution of @Julieng50 with @Extension
on the controller class seems to be good and natural for me. In the end your controller implementation is an extension of controller extension point.
Maybe @Julieng50 can show us a functional demo application that integrate Spring (MVC or Boot) and PF4J.
from pf4j-spring.
In the end if you don't use the extension mechanism from PF4J, what are you using from PF4J, only the plugin mechanism (load and start plugins)?
I think that would be possible in the future to use the @Controller
, @Service
, @Component
annotations from Spring, with PF4J-Spring without to use the @Extension
annotation from PF4J.
I wish to write below some theoretical aspects related to this subject.
In Spring we can have hierarchical application context, you can visualize these contexts as nodes in a tree (a hierarchy), a node (application context) could have one parent, siblings and children.
In PF4J each plugin contain other plugins as dependencies and also it can be a dependency for other plugins. You can visualize these plugins as node in a (directed) graph.
I think in the end that it's possible to traverse the dependencies graph from PF4J (it's available), and to create a Spring hierarchical application context for each Spring plugin (node) from the graph. We can add the application context of dependency plugin as parent context and the application context of dependent plugin (other plugins that depends on our plugin) as children context. It's a problem here that in Spring hierarchical application context we cannot have multiple parents.
Example:
P1 -> P2 -> P3 (plugin P1 is a dependency for P2 and P2 is a dependency for P3).
Each plugins is a Spring plugin (it comes with an application context). When we instantiate P3 we can specify that it application context has as parent the application context of P2, in this mode, all beans defined in P2 are available for P3 (but not vice versa).
from pf4j-spring.
@Julieng50 Can you share the source code of your plugin and Spring application or atleast the main class?
from pf4j-spring.
Hi,
yes, it would be cool if @Julieng50 shared the project (or a working sample). I am using that approach and the constructor of my RestController is being executed, but then when I type the URL in the browser I get a 404 error, so I guess I'm missing something :-D.
Anybody else is having the same issue?
from pf4j-spring.
Can we close this issue?
from pf4j-spring.
I haven't been able to get it working. I used @Julieng50 comment but I always get a 404 error.
I would like to use the framework in my projects and use the new version is l of spring boot, but it is not easy to get a project with a data source in the main context, rest controllers in the plugins and so on.
Do you plan to publish a whole example?
Regards :-)
from pf4j-spring.
Maybe the same problem is encountered in #18.
I see people that use PF4J with Spring (Boot) but I don't know why people using these two projects not share knowledge/projects .
I don't use Spring in my projects, so I cannot help more in this field.
Maybe someone with strong Spring knowledge will help us to move this module (pf4j-spring) forward.
I hope π .
from pf4j-spring.
EDIT: moved to #27
An example how to use @Entity
annotated (JPA/Hibernate) POJO classes in a plugin while the main app is a spring boot application (auto configuration; see JpaBaseConfiguration#getPackagesToScan() would be nice, too.
Cause as my plugin has different package names and another class loader they won't be picked up by getPackagesToScan
I guess you need to create your own LocalContainerEntityManagerFactoryBean
bean to call setPackagesToScan
yourself. But how to pick up all the plugin packages from pluginManager
bean?
from pf4j-spring.
Related Issues (20)
- 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
- Is there a plan to release version 0.9.0 or 0.8.1 to incorporate the changes from commit 5d26e9b? HOT 2
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.