the instance is not a cdi bean but get cdi injections (like JBatch
components for instance).
You can do this:
public class Router ... {
@Inject Listener listener;
@PostConstruct
public void init() {
listener.triggerMe(this);
}
public void listen(Sthg sthg) {
}
@AppScoped
public static class Listener {
private AtomicRef<Router> enclosing = new AtomicRef<>();
public void listen(@Observes Sthg sthg) {
enclosing.get().onEvent(sthg);
}
public void triggerMe(Router router) {
enclosing.set(router);
}
}
}
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>
2015-06-03 8:43 GMT-07:00 Alex Soto <[email protected]>:
> Last problem before I can send a summary of what I have done for
> implementing multitenancy. I have created an event which should be used for
> registering new tenants dynamically. And I have created an @Observes method
> in Router. The surprise is that the instance that is registered initially
> and the once it receives the event are different. I have annotated the
> router as @ApplicationScope but no luck.
> Any idea?
> Alex.
>
> El dc., 3 juny 2015 a les 14:55, Alex Soto (<[email protected]>) va
> escriure:
>
> > Now it works :D Now I will be able to send CDI events from one jar and
> > observes here the event and register a new tenant :D Thank you so much.
> >
> > El dc., 3 juny 2015 a les 14:37, Romain Manni-Bucau (<
> > [email protected]>) va escriure:
> >
> >> just qdd InitializeAfterDeployment = true in the router definition
> >>
> >>
> >> Romain Manni-Bucau
> >> @rmannibucau <https://twitter.com/rmannibucau> | Blog
> >> <http://rmannibucau.wordpress.com> | Github <
> >> https://github.com/rmannibucau> |
> >> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> >> <http://www.tomitribe.com>
> >>
> >> 2015-06-03 13:55 GMT+02:00 Alex Soto <[email protected]>:
> >>
> >> > Ok I have created a resources.xml and everything works perfectly, but
> >> > Person instance is still not injected and its value is null.
> >> >
> >> > Latest code is here: https://github.com/lordofthejars/multi
> >> >
> >> >
> >> > El dt., 2 juny 2015 a les 16:50, Romain Manni-Bucau (<
> >> > [email protected]>)
> >> > va escriure:
> >> >
> >> > > 3 notes:
> >> > >
> >> > > 1. if you let hibernate use the metadata at startup then ensure you
> >> have
> >> > a
> >> > > default datasource or just switch it off: <property
> >> > > name="hibernate.temp.use_jdbc_metadata_defaults"
> >> > > value="false" />
> >> > > 2. the injections are not working cause you use a container resource
> >> (no
> >> > > application), use resources.xml to get it activated
> >> > > 3. you dont need a server-jar.xml: properties.setProperty("My
> Router",
> >> > > "new://Resource?class-name=com.scytl.multi.DeterminedRouter");
> >> > >
> >> > >
> >> > > Romain Manni-Bucau
> >> > > @rmannibucau <https://twitter.com/rmannibucau> | Blog
> >> > > <http://rmannibucau.wordpress.com> | Github <
> >> > > https://github.com/rmannibucau> |
> >> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> >> > > <http://www.tomitribe.com>
> >> > >
> >> > > 2015-06-02 16:35 GMT+02:00 Alex Soto <[email protected]>:
> >> > >
> >> > > > Yes I am using 4.7.2, but it is not working. You can try it, the
> >> > project
> >> > > is
> >> > > > here: https://github.com/lordofthejars/multi
> >> > > >
> >> > > > El dt., 2 juny 2015 a les 16:13, Romain Manni-Bucau (<
> >> > > > [email protected]>)
> >> > > > va escriure:
> >> > > >
> >> > > > > Hi Alex
> >> > > > >
> >> > > > > Use 4.7.2
> >> > > > > Le 2 juin 2015 03:16, "Alex Soto" <[email protected]> a écrit :
> >> > > > >
> >> > > > > > Hi I am developing a Dynamic datasource routing component. I
> am
> >> > using
> >> > > > > > OpenEJB 4.7.1 for testing and I have seen that AbstractRoutes
> >> are
> >> > not
> >> > > > CDI
> >> > > > > > aware. Basically I have tried to inject a simple POJO but the
> >> > > instance
> >> > > > > is
> >> > > > > > null. I have the beans.xml in src/main/resources/META-INF so
> >> CDI is
> >> > > > > > enabled.
> >> > > > > >
> >> > > > > > Maybe this inner components are no CDI by default, any ideas?
> >> > > > > >
> >> > > > >
> >> > > >
> >> > >
> >> >
> >>
> >
>