User development,

A new message was posted in the thread "Lookup up a POJO service without 
injecting it inside -beans.xml?":

http://community.jboss.org/message/522436#522436

Author  : Martin N
Profile : http://community.jboss.org/people/MartinN

Message:
--------------------------------------------------------------
Zdravo Ales...
 
I tried to inject the service as you suggested (which also lets me preserve the 
interface) by implementing KernelControllerContextAware as such:
 
public class ServiceA implements KernelControllerContextAware {
    private KernelControllerContext controllerContext;
    private Logger log;
    private String val;
    private ServiceB svcB;
 
    public ServiceA() {
        log = Logger.getLogger(getClass().getName());
    }

    public String getValue() {
        return val;
    }
 
    public void setValue(String val) {
        this.val = val;
    }

    public ServiceB getServiceB() {
        return this.svcB;
    }

    public void setServiceB(ServiceB val) {
        this.svcB = val;
    }
 
    public void init() {
        try {
            log.info("lookup = " + 
controllerContext.getController().getInstalledContext("SvcB"));
        } catch (Throwable e) {
            e.printStackTrace();
        }
        log.info("init-ed");
    }

    public void create() {
        log.info("created");
    }

    public void start() {
        log.info("started");
    }

    public void stop() {
        log.info("stopped");
    }

    public void destroy() {
        log.info("destroyed");
    }
 
    @Override
    public void setKernelControllerContext(KernelControllerContext arg0)
            throws Exception {
        this.controllerContext = arg0;
    }
 
    @Override
    public void unsetKernelControllerContext(KernelControllerContext arg0)
            throws Exception {
        this.controllerContext = null;
    }
 
 
and ServiceB.java is:
 
package com.raf.test;
 
import org.jboss.logging.Logger;
 
public class ServiceB {
 
    private Logger log;    private String val;
 
    public ServiceB() {        log = Logger.getLogger(getClass().getName());    
}        public String getValue() {        return val;    }
 
    public void setValue(String val) {        this.val = val;    }
 
    public void init() {        log.info("init-ed");    }        public void 
create() {        log.info("created");    }        public void start() {        
log.info("started");    }        public void stop() {        
log.info("stopped");    }        public void destroy() {        
log.info("destroyed");    }}
 
 
and here's the deployment descriptor:
 
 
 
 
The problem is 'getInstalledContext("SvcB")' doesn't work. It returns a null. 
For "SvcA" it returns the pojo instance - which leads me to believe there's 
some scoping at play and that I need to probably search in the 'root' scope of 
the <deployment> file for my bean, but I'm not familiar how to do that, and I 
couldn't find some simple example to show me how to do that....
 
My original point is - I don't want to inject the service via the descriptor - 
I know I can do <inject bean="SvcB"/> in SvcA, but I don't want to do that - 
this is why I asked, is it possible to somehow locate "SvcB" from inside "SvcA"?
 
Thanks!
 
Martin

--------------------------------------------------------------

To reply to this message visit the message page: 
http://community.jboss.org/message/522436#522436


_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to