[BLOSSOM-39] Spring @Scope annotation doesn't appear to work Created: 25/Jan/11 Updated: 07/Nov/14 Resolved: 27/Jan/11 |
|
| Status: | Closed |
| Project: | Blossom |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Neutral |
| Reporter: | Dave Lloyd | Assignee: | Tobias Mattsson |
| Resolution: | Workaround exists | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Template: |
|
| Acceptance criteria: |
Empty
|
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
| Bug DoR: |
[ ]*
Steps to reproduce, expected, and actual results filled
[ ]*
Affected version filled
|
| Date of First Response: |
| Description |
|
The following code works fine without the @Scope annotation (this code doesn't need the annotation actually, but it is self-contained and demonstrates the problem) package uk.co.moviestorm.hub.paragraphs; import info.magnolia.module.blossom.annotation.Paragraph; /**
@TabFactory("Content") } With the annotation, I get the following exception: 011-01-25 14:43:37,667 ERROR info.magnolia.cms.taglibs.Include : Can't find renderable definition text |
| Comments |
| Comment by Tobias Mattsson [ 26/Jan/11 ] |
|
Hi Dave, When you add scope to a controller it has its initialization deferred until it is first needed to serve a request. Therefore its not detected by blossom when it starts up and searches for controllers annotated with @Paragraph. This is the reason for the problem you're seeing. Magnolia throws an error saying 'renderable definition not found' since the paragraph hasn't been registered. Although this part could be rewritten to handle this scenario there's another problem with this approach. Controllers are also called to create dialogs and at that point an instance is needed. Setting scope on objects used by your controller on the other hand works as expected. So the answer will have to be that no, adding scope on the controller is not supported. I don't expect this to be a huge inconvenience as the usual use case is to have controllers singleton scoped and stateless. If it is indeed a problem for you please explain more about why you need this setup and why its beneficial. // Tobias |
| Comment by Dave Lloyd [ 26/Jan/11 ] |
|
Hi Tobias, Thanks for investigating this and your considered reply. That makes perfect sense to me. I'm still finding my feet with Spring & Blossom, converting an old school servlet site to work in a new way. Thanks, |
| Comment by Tobias Mattsson [ 27/Jan/11 ] |
|
Hi Dave, You can add seesion scope to for instance the user object and have that injected into the stateless controller. Spring will create a proxy that delegates calls to the actual instance in the session. @Component @Scope("session") public class User {...} @Paragraph("Text") @Controller public class TextParagraph { @Autowired private User user; ... } Then load them using component scan with scoped-proxy set to targetClass. <context:component-scan base-package="info.magnolia.blossom.sample" scoped-proxy="targetClass" />
The controller is stateless but needs no boiler plate code to find the objects it needs. // Tobias |