PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/content/server/framework/atlassian-sdk/automatic-generation-of-spring-configuration.md

https://bitbucket.org/zchristmas/atlassian-sdk-docs
Markdown | 85 lines | 62 code | 23 blank | 0 comment | 0 complexity | 2a4ddd8feeceb1c136e565bf9a9eeacb MD5 | raw file
Possible License(s): LGPL-2.0
  1. ---
  2. aliases:
  3. - /server/framework/atlassian-sdk/automatic-generation-of-spring-configuration-852044.html
  4. - /server/framework/atlassian-sdk/automatic-generation-of-spring-configuration-852044.md
  5. category: devguide
  6. confluence_id: 852044
  7. dac_edit_link: https://developer.atlassian.com/pages/editpage.action?cjm=wozere&pageId=852044
  8. dac_view_link: https://developer.atlassian.com/pages/viewpage.action?cjm=wozere&pageId=852044
  9. date: '2017-12-08'
  10. guides: guides
  11. legacy_title: Automatic Generation of Spring Configuration
  12. platform: server
  13. product: atlassian-sdk
  14. subcategory: learning
  15. title: Automatic generation of Spring configuration
  16. ---
  17. # Automatic generation of Spring configuration
  18. The Atlassian Plugin Framework uses <a href="http://www.springframework.org/osgi" class="external-link">Spring</a> to implement many of its features for OSGi plugins by automatically generating Spring XML configuration files. This generation occurs as several steps in the [OSGi plugin -&gt; OSGi bundle transformation](/server/framework/atlassian-sdk/going-from-plugin-to-osgi-bundle) that happens at plugin installation. These steps are:
  19. 1. Component Import transformation
  20. 2. Component transformation
  21. 3. Host component imports
  22. 4. Module Type transformation
  23. #### Component Import Transformation
  24. The [Component Import](/server/framework/atlassian-sdk/component-import-plugin-module) module type allows a plugin to import a component exposed by another plugin or by the host application itself. These elements are converted into the Spring configuration file `META-INF/spring/atlassian-plugins-component-imports.xml` as Spring DM `<osgi:reference>` elements. See the <a href="http://static.springsource.org/osgi/docs/1.1.3/reference/html/service-registry.html#service-registry:refs" class="external-link">Spring DM documentation</a>.
  25. In their place, a placeholder module descriptor is stored in the plugin framework so that the import will appear in the list of plugin modules. However, disabling it has no effect.
  26. #### Component Transformation
  27. The [Component](/server/framework/atlassian-sdk/component-plugin-module) module type allows a plugin to make an object available for dependency injection within the plugin, and with the 'public' flag, also expose that instance to other plugins, accessible via the Component Import module type. The transformation that occurs upon installation converts these elements into Spring `<beans:bean>` elements in a configuration file called `META-INF/spring/atlassian-plugins-components.xml`. If the 'public' flag is set to true, the bean instances are also exposed via the Spring DM `<osgi:service>` element. See the <a href="http://static.springsource.org/osgi/docs/1.1.3/reference/html/service-registry.html#service-registry:export" class="external-link">Spring DM documentation</a>.
  28. Like the Component Import module type, in their place, a placeholder module descriptor is stored in the plugin framework so that the component will appear in the list of plugin modules. However, disabling it has no effect.
  29. #### Host Component Imports
  30. Upon plugin installation, the plugin framework will scan the classes in the plugin JAR for any references to host components. If any are detected, the framework will generate the Spring configuration file `META-INF/spring/atlassian-plugins-host-components.xml` to add a bean for each host component needed. Since host components are always available and do not change during runtime, the bean definitions are special purpose beans that import the host component services on startup. The Spring DM `<osgi:reference>` element is not used, because it adds a lot of overhead that is not necessary here. You can override the beans by using the `<component-import>` element to specify a different bean name, since if the plugin framework detects an import for a host component, it will not generate a bean reference.
  31. This is an example of a generated host component reference named 'foo':
  32. ``` xml
  33. <beans:bean id="foo" class="com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean">
  34. <beans:property name="filter" value="(&amp;(bean-name=foo)(plugins-host=true))"/>
  35. </beans:bean>
  36. ```
  37. The 'bean-name' is provided to the plugin framework by the application on initialisation, and the 'plugins-host' property is used to further restrict the filter to just host components.
  38. #### Module Type Transformation
  39. The [Module Type](https://developer.atlassian.com/display/PLUGINFRAMEWORK/Module+Type+Plugin+Module) module allows a plugin to define its own plugin module types that it and other plugins can use. At installation time, it generates a bit of Spring configuration in a file named `META-INF/spring/atlassian-plugins-module-types.xml` to expose the appropriate `com.atlassian.plugin.ModuleDescriptorFactory` instance.
  40. Here is an example of a module type 'foo' that uses the `my.FooDescriptor` module descriptor instance:
  41. Code in `atlassian-plugin.xml`:
  42. ``` xml
  43. <module-type key="foo" class="my.FooDescriptor" />
  44. ```
  45. Code in `META-INF/spring/atlassian-plugins-module-types.xml`:
  46. ``` xml
  47. <beans:bean id="springHostContainer" class="com.atlassian.plugin.osgi.bridge.external.SpringHostContainer"/>
  48. <beans:bean id="moduleType-foo" class="com.atlassian.plugin.osgi.external.SingleModuleDescriptorFactory">
  49. <beans:constructor-arg index="0" ref="springHostContainer"/>
  50. <beans:constructor-arg index="1">
  51. <beans:value>foo</beans:value>
  52. </beans:constructor-arg>
  53. <beans:constructor-arg index="2">
  54. <beans:value>my.FooDescriptor</beans:value>
  55. </beans:constructor-arg>
  56. </beans:bean>
  57. <osgi:service id="moduleType-foo_osgiService" ref="moduleType-foo" auto-export="interfaces"/>
  58. ```
  59. The `SpringHostContainer` bean is only created once per plugin, providing the ability to instantiate module descriptor instances using the plugin's Spring container. This means the module descriptor class 'FooDescriptor' can support constructor dependency injection for host and plugin components.
  60. ##### RELATED TOPICS
  61. [Going from Plugin to OSGi Bundle](/server/framework/atlassian-sdk/going-from-plugin-to-osgi-bundle)
  62. [Plugin Framework](https://developer.atlassian.com/display/PLUGINFRAMEWORK/Plugin+Framework)