Polish | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
WstępKażda wtyczka ma własny kontekst aplikacji (ApplicationContext), w którym rejestrowane są jej komponenty, kontrolery, importowane serwisy etc. Dzięki temu wtyczka może być pisana tak jak każda inna aplikacja wykorzystująca SpringFramework. Kontekst może być konfigurowany na 2 sposoby:
Konfiguracja XMLJeżeli wtyczka zawiera plik /META-INF/spring/plugin-context.xml, to na jego podstawie tworzony jest XmlOsgiPluginContext.
Plik konfiguracji jest standardowym plikiem konfiguracji kontekstu aplikacji springframework i może wyglądać następująco:
Konfiguracja JavaOd SpringFramework 3 możliwa jest konfiguracja kontekstu aplikacji w całości używając klas Java oznaczonych adnotacją @Configuration. Jeżeli mechanizm wtyczek nie znajdzie pliku /META-INF/spring/plugin-context.xml to stworzy domyślny kontekst aplikacji, który skanuje całą wtyczkę w poszukiwaniu klas @Component (a więc również @Configuration).
Przykładowa konfiguracja (rejestruje tylko 1 bean klasy String):
|
English | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
IntroductionEach plugin has its own application context (ApplicationContext), where its components, controllers, imported services etc. are registered. This allows the plug-in to be written just like any other application using SpringFramework. The context can be configured in 2 ways:
XML configurationIf the plugin contains the /META-INF/spring/plugin-context.xml file XmlOsgiPluginContext is created based on it.
The configuration file is a standard springframework application context configuration file and can look like this:
Java configurationSince SpringFramework 3, it is possible to configure the application context entirely using Java classes marked with the @Configuration annotation. If the plugin engine does not find the /META-INF/spring/plugin-context.xml file it will create a default application context that scans the entire plugin for @Component (and thus also @Configuration).
Example configuration (registers only 1 bean of class String):
|