You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@karaf.apache.org by "Terrien Jean-Yves (JIRA)" <ji...@apache.org> on 2018/05/09 15:18:00 UTC

[jira] [Updated] (KARAF-5743) How To create command with bean injection

     [ https://issues.apache.org/jira/browse/KARAF-5743?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Terrien Jean-Yves updated KARAF-5743:
-------------------------------------
    Summary: How To create command with bean injection  (was: Hawto create command with bean injection)

> How To create command with bean injection
> -----------------------------------------
>
>                 Key: KARAF-5743
>                 URL: https://issues.apache.org/jira/browse/KARAF-5743
>             Project: Karaf
>          Issue Type: Question
>          Components: karaf-core
>    Affects Versions: 4.0.9
>         Environment: smx 7.0.1 karaf 4.0.9
>            Reporter: Terrien Jean-Yves
>            Priority: Major
>
> Hi,
> I have a karaf 2.2.2 bundle that I wear to karaf 4.0.9.
> I rewrite everything.
> I did not find how to make command with a bean injections.
> I've old blueprint
> with services reférences
> <reference id="config" timeout="20000" interface="javax.sql.DataSource" filter="(name=config)" />
> ...
> beans declarations
> <bean id="fluxNameCompleter" class="fr.aphp.ati.eai.hermes.command.hermes.completer.FluxNameCompleter">
>  <property name="dataSource" ref="config" />
> <property name="context" ref="blueprintBundleContext" />
>  </bean>
> <bean id="conteneur" class="fr.aphp.ati.eai.hermes.command.db.service.Contener">
>  <argument ref="environnement" type="fr.aphp.ati.eai.hermes.services.environnement.Environnement"/>
>  </bean>
> and commands
> <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
> <command name="hconfig/composants">
>  <action class="fr.aphp.ati.eai.hermes.command.hermes.command.ShowComposantsCommand">
> <property name="conteneur" ref="conteneur" />
>  </action>
>  <completers>
>  <ref component-id="fluxNameCompleter" />
>  </completers>
>  </command>
> </command-bundle>
>  
> in the completers or commands I use the beans defined in blueprint.
> I have some command that also uses bundlecontext and session.
> for context a simple injection is enough
> <command name="hconfig/trace">
> <action class="fr.aphp.ati.eai.hermes.command.hermes.command.TraceCommand">
> <property name="context" ref="blueprintBundleContext" />
> </action>
> </command>
> and for the session it is received as a parameter of the method executes
>  
> in karaf 4, the blueprint solution does not work
> I've replaced xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0" bye xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"
> I'vre removed all commands name
> the comands can not be deployed.
> ComponentDefinitionRegistryImpl.registerComponentDefinition return error invalid id for the component.
>  
> I've tried the annotations and Karaf-Commands=* in manifest
> the simple command helloword works but no injections are made
> i do not have any context no session no beans i declare in blueprint
> in excute method of TraceCommand context and session are null.
> in all command class and all completer class, all  @Reference returns null
> if I remove my beans like Contener, they are never instantiated.
> how to define a command that uses a custom bean?
> How to access the context and the session?
> Where then how to make blueprint work?
> A+JYT
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)