deltaspike-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Porter <lightguard...@gmail.com>
Subject Re: BeanProvider.InjectFields(this) limitation with static field
Date Thu, 05 Jul 2012 13:39:35 GMT
I'm fine with that. Statics don't work well with CDI anyway (due to how
they work at the bytecode level and with proxies).

On Wed, Jul 4, 2012 at 3:38 AM, Charles Moulliard <cmoulliard@gmail.com>wrote:

> Hi,
>
> As BeanProvider.InjectFields(this) does not work with static field, I would
> like to suggest that we change the javadoc of the field
>
>     /**
>      * Allows to perform dependency injection for instances which aren't
> managed by CDI
>      * <p/>
>      * Attention:<br/>
> *     * The resulting instance isn't managed by CDI, only non static fields
> annotated with @Inject get initialized.*
>      *
>      * @param instance current instance
>      * @param <T> current type
>      * @return instance with injected fields (if possible - or null if the
> given instance is null)
>      */
>     @SuppressWarnings("unchecked")
>     public static <T> T injectFields(T instance)
>
> Here is an example
>
> public class BootStrap {
>
>     final private static Logger logger =
> LoggerFactory.getLogger(BootStrap.class);
>
>     @Inject @CamelRouteCategory(Category.SIMPLE)
>     public static BootCamel bc;
>
>     public static void main(String[] args) throws Exception {
>
>         CdiContainer cc = CdiContainerLoader.getCdiContainer();
>         cc.boot();
>         cc.getContextControl().startContexts();
>         logger.info(">> CDI container started");
>
>         BootStrap bs = new BootStrap();
>         BeanProvider.injectFields(bs);
>
>         // Call init method to start camel route
>         bc.init(); // NPE is generated here
>         ....
>
> public class BootCamelFactory {
>
>     @Produces
>     @CamelRouteCategory(Category.SIMPLE)
>     public static BootCamel simple() throws Exception {
>         return (BootCamel) new SimpleCamelRoute();
>     }
>
> Regards,
>
>
>
> -----
> Apache Committer / Sr. Pr. Consultant at FuseSource.com
> Email: [hidden email]
> Twitter : @cmoulliard, @fusenews
> Blog : http://cmoulliard.blogspot.com
> --
> View this message in context:
> http://apache-deltaspike-incubator-discussions.2316169.n4.nabble.com/BeanProvider-InjectFields-this-limitation-with-static-field-tp4652980.html
> Sent from the Apache DeltaSpike Incubator Discussions mailing list archive
> at Nabble.com.
>



-- 
Jason Porter
http://lightguard-jp.blogspot.com
http://twitter.com/lightguardjp

Software Engineer
Open Source Advocate
Author of Seam Catch - Next Generation Java Exception Handling

PGP key id: 926CCFF5
PGP key available at: keyserver.net, pgp.mit.edu

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message