Hi All,

Please see my setup and code. 

Version: apache-karaf-3.0.5

*Part 1*: Service class

Service:
------------
package org.jrb.test;

public interface MyService {

    public String echo(String message);

}

package org.jrb.test;

public class MyServiceImpl implements MyService {

    public String echo(String message) {
        return "Echo processed: " + message;
    }

}

Blueprit:
------------
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
default-activation="lazy">

    <bean id="serviceBean" class="org.jrb.test.MyServiceImpl"/>

    <service id="MyService" ref="serviceBean" 
interface="org.jrb.test.MyService"/>

</blueprint>

i can see my service in list: 
------------------------------------------
onos> service:list | grep serviceBean
 *osgi.service.blueprint.compname = serviceBean*


*Part 2*: consumer class for testing

Blueprint
-------------
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; 
default-activation="lazy">

<reference id="MyService" interface="org.jrb.test.MyService"/>
<bean id="b" class="org.ct.command.AddCommand" activation="eager" >
<property name="serviceBn" ref="MyService" />
</bean>
    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0";>
        <command>
            <action class="org.ct.command.AddCommand"/>
        </command>
    </command-bundle>
    
</blueprint>

In Java:
------------
package org.ct.command;

import org.apache.felix.gogo.commands.Action;
import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.service.command.CommandSession;

import org.jrb.test.MyService;

@Command(scope = "onos", name = "service-add", description = "Adds a 
Client")
public class AddCommand implements Action {

public AddCommand()
{
}

private MyService serviceBn;
        
        public void setServiceBn(MyService serviceBn)
        {
        this.serviceBn = serviceBn;
        }
    
    public MyService getServiceBn() {
return service;
}

   @Override
    public Object execute(CommandSession session) throws Exception {
         System.out.println("Executing command add");

         if(serviceBn != null)
        System.out.println("serviceBn is not null");
         else
        System.out.println("serviceBn is null !!");
         if(serviceBn != null)
        System.out.println(serviceBn.echo("testing....."));

    }
}

In the above code, if i run the command "service-add",  my serviceBn is 
always NULL. The reference is not injecting the bean. 

Is there anything missing in my code? please help. 


Regards,
Jayanth


-- 
-- 
------------------
OPS4J - http://www.ops4j.org - [email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to