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
Try to express my problem #1
Conversation
* I have a bean that depends on servletContext | ||
*/ | ||
@Bean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be a bean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would need to use it in other parts of the application.
In CometD context this bean will be a BayeuxServer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that won't work for sure. Can you give this a try?
public class DemoBean implements ApplicationListener<ApplicationStartedEvent> {
....
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
this.servletContext = ((WebApplicationContext) applicationContext).getServletcontext();
}
}
I know you don't but that's how BPP should be ideally defined in Spring Land. Such beans are created very early in the lifecycle and making them static makes it easier to express they don't carry too much dependencies. Certainly a BPP that depends on a bean that depends on ServletContext is creating an impossible cycle for the context to resolve when the context is starting as part of the application lifecycle. |
Also I hate to say this but building a Perhaps this is something that the |
Thanks a lot for your proactive help! I will take a look after the holidays and get back to you. If I struggle too much there is an alternative path for me to take. CometD supports running without processing annotations also. |
I think I have found a solution at least. I don't particularly like it but I still have another option to explore which is not asking cometd to process annotations. Thanks for your help! |
Sure thing. By solution, you mean catching that technical exception? If so, please don't do that. Using an ObjectProvider with late resolution seems much more aligned with what's actually happening. |
I wasn't aware of |
Sorry not enough coffee here. I meant ApplictionContextAware. While the context that you'll get injected on startup will have a null servlet context you can keep the reference and access the servlet context later. You can also implement that on the BPP if you need it as this a safe callback that doesn't trigger early init. Long story short: you can inject something early that will get you access to the context once the app has started. ObjectProvider would work if we'd register the servlet context down the road but we don't for jar deployment which I think is a bug we need to fix. If you update this sample here with the proposal I am happy to review and guide further. Thanks for the follow up! |
Sorry, I don't understand. Our Anyway, sorry to say this but I have to move on with my tasks. I have prompted for a different solution and now I simply post process the specific beans manually without using BPP. Feel free to close all of my issues. |
Thanks a lot for your help though! Much appreciated! |
We already saw that this isn't possible. That bean will have to defer access to the servlet context. One way to do that is to inject Having said all of that, I agree this issue has run its course now. Glad you got it working! |
I don't really need
DemoPostProcessor
to be initialized statically. I need it to be initialized after constructing aHello
bean withServletContext
.