Pluggable Placeholders dont work when using Component in Java Constructor

32 views
Skip to first unread message

ray charley

unread,
May 27, 2020, 12:02:32 PM5/27/20
to Scroll Viewport Developers
Hello Guys,

we have been creating custom Placeholders  for different tasks on our viewport (mostly helper functions) and it worked fine.

Now we are trying to use Components like the "PageManager" or the "ContentPropertyManager"  to do more complex tasks but it just doesn't work.

This basic code below will only work if we remove the PageManager/ContentPropertyManager etc...  from the Contructor. 

The system just deactivate the modul without any log entry(even after been reactivated). We've got the same beharvior on all our systems (local, dev, staging, prod). Some are running Confluence 6 and other Confluence 7 in the latest available versions.




import com.atlassian.confluence.pages.PageManager;

public class InternProcPlaceholder {

    private PageManager pageManager;
  
    public InternProcPlaceholder (PageManager pageManager ) {
         this.pageManager = pageManager;
    }

    public String get(String pageId, String propertyKey) {
        Page page = pageManager.getPage(Long.parseLong(pageId)); // Only a test
        return "It Works";
    }

    public String getTest() {
        return "It also Works";
    }  
}



Any Idea what could be the Problem?

Thanks and Regards,

Charly

ray charley

unread,
Jun 9, 2020, 3:22:42 AM6/9/20
to Scroll Viewport Developers
Any Ideas?

Michael Rudolph

unread,
Jul 1, 2020, 9:44:36 PM7/1/20
to Scroll Viewport Developers
Hey Charley,

I think I had the same issue like you. What helped in my case was adding the @ComponentImport annotation, e.g. like this:

public class InternProcPlaceholder {
@ComponentImport
private PageManager pageManager;
...
}

Further, I started my project using the boilerplate created by the atlassian-sdk and not the sample repo by k15t, which seems outdated to me.

Kind Regards,
Michael

On Tuesday, June 9, 2020 at 9:22:42 AM UTC+2, ray charley wrote:
Any Ideas?

Jens Rutschmann (K15t)

unread,
Jul 2, 2020, 10:45:55 AM7/2/20
to scroll-vi...@googlegroups.com
Hi,

Michael is right. You may need some annotations on either the field (and then don't use any constructor parameters) or on the parameters in
the constructor.

Which one you need depends on how your plugin project is set up:

You probably have a 'transformless' plugin (your pom.xml contains "<Atlassian-Plugin-Key>" inside the "<instructions>" tag) because
otherwise your constructor should have worked (I just verified that the example plugin installs fine on Confluence 7.3).

In that case you should add the @ComponentImport annotation as Michael mentioned on all fields or constructor parameters for managers /
services that are not defined in your plugin and @Autowired or @Inject for all that are from within your plugin (in case you have any).

If your plugin is not transformless then you can try @Autowired or @Inject, or just create a setter for the PageManager field and spring
will call that one when the module is enabled.


More on transformless plugins can be found here, but it's sort of an advanced task to mess with that stuff, so it's better just to use the
approach the SDK generates nowadays (it generates transformless plugins by default).
https://bitbucket.org/atlassian/atlassian-spring-scanner


Cheers,
Jens
Reply all
Reply to author
Forward
0 new messages