-
Notifications
You must be signed in to change notification settings - Fork 825
[WW-5173] - Attempt to fix DI behaviour for custom cache factories #573
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
[WW-5173] - Attempt to fix DI behaviour for custom cache factories #573
Conversation
- Update to use consistent name for expression and BeanInfo factories in default configuration implementation and provider. - Add inject annotation to the non-default constructor to ensure the proper constructor is called during DI for containers. - Use fully-qualified factory names for defaults in default.properties. - Ensure unique types for each cache factory in struts-default.xml
Thank you so much @JCgH4164838Gh792C124B5 ! I remember that I also had some same difficulties when I was working on #167 . Finally I simply workaround it by injecting Container itself and getting required bean instead of injecting the bean itself. This isn't a good practice albeit, as Lukasz commented there. But this is what I could and able to do that time to make it working. Even with a lot debugging. I'm trying to say that your case is same but more complex, i.e. with constructor injection with multiple overloaded constructors. But you were able to make it work with no hack. So I think now you know DI better than any of us and your changes are best possible solution :) BTW I found all usages of And could you please explain a bit more about:
Thanks again! |
Hello @yasserzamani . Thanks for taking a look and providing feedback. 😄 I will attempt to respond to your question for more detail on the container construction still using the default implementations. The information is based on stepping through breakpoints using a sample application with a custom expression cache factory configured. The In neither case is the custom cache factory dependency recognized as being present to be injected. In the test application, when So, the custom factory instance appears to be wired-up correctly, but something is still missing. Maybe a I am not sure what else to try at this point, something in my understanding of the mechanism seems to be missing ... 😞 |
Thank you so much @JCgH4164838Gh792C124B5 for the explanation! Yes I remember too in past I was observing multiple hits on a breakpoint during injections, provided I expected one hit. Could you please somehow share that sample app including breakpoints places? I can take a look when I find some free cycles :) thanks again for your works! |
Hello @yasserzamani . Thanks for the update. I attached a sample application project (S2_StarterApp_1.zip) to the WW-5173 JIRA as a .zip file (it is just a struts2-archetype-starter Maven Archetype project with an attempt to wire in a custom cache factory implementation). Unfortunately, my IDE does not seem to have a breakpoint export facility, so I put a comment in the One other note, I think the recent naming changes for the DTD from 2.6 to 6.0 was causing issues, as I had to adjust the sample application configuration to use 6.0.0 (rather than 6.1.0-SNAPSHOT) in order to successfully deploy it for interactive debugging. |
Thank you very much @JCgH4164838Gh792C124B5 ! I've been working on it today. You're right, doesn't work as expected, provided it's added similarly like ActionProxyFactory. I'll work on it in next days :) thanks again! |
Hi @JCgH4164838Gh792C124B5 sorry I was wrong yesterday. Your sample app works, however you need to apply a few fixes on your previous work which I introduced by #581 - I learnt them from already working extension points like ObjectFactory and ActionFactory. Please feel free to either merge my PR and rebase your PR based on it, or simply redo same fixes on your PR and close my PR please. Thanks again for your works! and sorry for my late answer. BTW regarding DTD problem, please apply following patch on your sample app Index: src/main/resources/struts.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/resources/struts.xml (date 1659109456598)
+++ src/main/resources/struts.xml (date 1659109456598)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.6//EN"
- "http://struts.apache.org/dtds/struts-2.6.dtd">
+ "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
+ "http://struts.apache.org/dtds/struts-6.0.dtd">
<struts>
|
- Incorporate changes from Y. Zamani's PR apache#581 manually, which appears to fix the previous issue that prevented customized cache factory implementations from being used (tested with sample app). Credit goes to Yasser Zamani for the fixes. - Updated unit tests and slight modifications to the changes from the PR apache#581.
Hi @yasserzamani . Thank you so much for taking a look, determining what was failing, and creating PR #581 to show a working solution. 😄 I was not certain I could do a merge/rebase of your PR correctly, so I just implemented the equivalent changes in this PR (with some slight modifications). |
Thank you @JCgH4164838Gh792C124B5 for testing bits!
For me too. Today I also tried a lot to make it working as you planned in previous version. Finally instead of I fixing Struts, it fixed me :)) and taught me that looks like that when you want to introduce an extension point, then you shouldn't use a concrete name in At bottom this LGTM and will merge. Just one thing. A few tests which are from past and not related, are deleted, I think by mistake, right? If so, then could you revert them. thanks! |
I added an example app using custom cache implementations and it works with this PR 💯 |
Hi @yasserzamani. Thanks for the review, and more background on the DI and alias behaviour. 😄
The Please let me know if the above makes sense, and if you agree the test changes are valid ? If not, I can restore the deleted tests and make changes to pattern them like |
I have been told struts is obsolete. Is it true ? Then how come developers are adding new features ? Give me a insight on this |
@JCgH4164838Gh792C124B5 thanks for clarification! LGTM 👍 |
@DeepakLalchandani thanks for asking! But please ask in Struts user mailing list instead where you will reach very more people (and more related people) than here. |
@DeepakLalchandani you probably heard rumour about Apache Struts 1 EOL - for more info please ask your question on the mailing list as suggested by Yasser. |
Hello Apache Struts Team.
This is an initial attempt to fix the dependency-injection behaviour for the custom expression and BeanInfo cache factory mechanism introduced in 6.0.0 (was 2.6). It took a fair amount of debugging and playing with configuration values to arrive at a small number of changes.
With these changes, and a custom implementation, it seems that
Container
getInstance(type, name)
will now return the custom implementation. That is an improvement, but the default container instance construction ofOgnlUtil
still seems to use the default implementations (so it seems something is still missing at this point).Please advise if anyone can see additional changes that might resolve the remaining issue(s) for custom cache factory assignment.