REST Services on Platform 7 / Confluence 9

I do not understand how we should deal with REST Services (v2 Platform 7 / Confluence 9) and Spring Java Config.

The example project on https://bitbucket.org/atlassian_tutorial/atlassian-plugins-osgi-javaconfig-demo/src/master/src/main/java/com/atlassian/plugins/example/javaconfig/config/MyJavaConfig.java shows that REST services are not explicitly set in the Configuration. The REST services are configured in the atlassian-plugin.xml and the injection seem to work without further configuration. But this example is for Platform 5 …

In REST Upgrade Guide we can read that we need to add the @Inject (see “Add @Inject to the constructor of the resource and provider classes”), but it is unclear

  1. if we need to do this despite we use Spring Java Config
  2. if we need to write a Configuration for REST Services (or Macros) on Platform 7 as we do it for other services (components), although it is not necessary for previous versions

I can start the app with Confluence 9.0.3 without mentioning REST Services / Macros in the Spring Java Config Configuration. But maybe this is only by coincidence?

What is the correct way of using REST services on Platform 7 / Confluence 9 with Spring Java Config regarding the @Inject topic in the Upgrade Guide?

IMHO it would be helpful if the Upgrade Guide could be explicitly mention this for users of Spring Java Config on https://bitbucket.org/atlassian/atlassian-rest/src/8.0.x/UPGRADE_720.md. But maybe this is just me … :slight_smile:

2 Likes

Hi! I didn’t have to do any REST Service migration, but I tested a simple app using Confluence 9 and Spring Java Config, and nothing changed. On the other hand, @Inject should never be used, classes in Spring with a single constructor use that as default, and this is the recommended way of injecting beans.

Regards,
Ansgar

1 Like

Hi @AnsgarNell,

Thank you for your reply!

It is helpful to know that @Inject does not apply when using Spring Java Config.

I have the REST services configured via Spring Java Config and this seems to be required. Otherwise I could deploy the app successfully, but get an error when I actually use the REST service.

I do not provide injection for macros the same way, but maybe I should?

It would be helpful if there was some official documentation that would make clear, what we need to cover in the configuration classes of Spring Java Config.

Did you try to annotate the REST Service with the @Service annotation? I didn’t need to configure it via Spring Java Config.

Thank you for your reply!

I do not use @Service.

It seems that if REST services work by configuring it with Spring Java Config (as I do to do injection for all other components/services).

But since I register REST Services and Macros in the atlassian-plugin.xml, it is just not clear to me, what Confluence expects when I use Spring Java Config and REST v2 on Platform 7. Do macros still work without extra configuration in Spring Java Config because of some backward-compatibility layer I am using, but not aware of? Does it harm if I configure REST Services with Spring Java Config because on some weird configuration (I am using or will be using on the next Confluence upgrade :melting_face:) registers the services twice?

I just would hope that there is some documentation (besides REST Upgrade Guide and the sample project with Spring Java Config and REST v1 or REST v2 and Spring Scanner) for developers that specifies what to do. I assume there is one, but I just cannot find it … links from the REST Upgrade Guide to that information would be helpful, at least for me …