Antw.: @PostConstruct and @Inject methods in superclasses

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Antw.: @PostConstruct and @Inject methods in superclasses

Arne Limburg
Hi,
for @Inject there is an order specified in JSR 330. Imho we should specify that same order for @Postconstruct if we have specification for it yet.

Regards,
Arne

----- Reply message -----
Von: "Stuart Douglas" <[hidden email]>
Datum: Fr., Sep. 30, 2011 23:58
Betreff: [cdi-dev] @PostConstruct and @Inject methods in superclasses
An: "Mark Struberg" <[hidden email]>
Cc: "cdi-dev" <[hidden email]>


This is actually covered by the interceptors specification, from memory I am pretty sure the base class method is mean't to be called first, but the spec gives you the full order.

@Inject methods are called before @PostConstuct (the are called in InjectionTarget.inject, which gets called before InjectionTarget.postConstruct).

I don't think we specify an order for @Inject methods.

Stuart

On 01/10/2011, at 5:47 AM, Mark Struberg wrote:

> Hi!
>
> JSR-250 common annotations is pretty thin about having @PostConstruct in multiple class hierarchies. It just says that there must only be one single method annotated with @PostConstruct in a class. Thus my question:
>
> If I have
>
>
> public class Animal {
>  @PostConstruct
>
>  public void doInit() {..}
>  ..
>
> }
>
> and
>
>  public class Horse extends Animal {
>  @PostConstruct
>
>  public void doSomeOtherInit() {..}
>  ..
>
> }
>
>
> 1.) for a contextual instance of Horse, will Animal#doInit() get executed or only the one from the 'effective' class?
> 2.) if 1.) was yes, then In which order do they get executed? Is this specced somewhere?
>
> 3.) Same scenario with @Inject methods. Do we specify an order?
>
> 4.) Both classes have @Inject methods and @PostConstruct. Again: which order of invocaition?
>
>
> Just that you understand my intention: we had a @PostConstruct method in Horse which did set a 'cached' flag in Animal. Turned out that this was a random generator depending on the intsalled server ;)
>
>
> LieGrue,
> strub
>
> _______________________________________________
> cdi-dev mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/cdi-dev


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev

_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev
Reply | Threaded
Open this post in threaded view
|

Re: Antw.: @PostConstruct and @Inject methods in superclasses

Mark Struberg
Yes, imo the things which are not yet clear are the order between @Inject and @PostConstruct, and wha happens if we have a class hierarchy.

LieGrue,
strub

--- On Fri, 9/30/11, Arne Limburg <[hidden email]> wrote:

From: Arne Limburg <[hidden email]>
Subject: Antw.: [cdi-dev] @PostConstruct and @Inject methods in superclasses
To: "[hidden email]" <[hidden email]>, "[hidden email]" <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
Date: Friday, September 30, 2011, 10:18 PM


 
 



 Hi,
for @Inject there is an order specified in JSR 330. Imho we should specify that same order for @Postconstruct if we have specification for it yet.

Regards,
Arne

----- Reply message -----
Von: "Stuart Douglas" <[hidden email]>
Datum: Fr., Sep. 30, 2011 23:58
Betreff: [cdi-dev] @PostConstruct and @Inject methods in superclasses
An: "Mark Struberg" <[hidden email]>
Cc: "cdi-dev" <[hidden email]>

 


This is actually covered by the interceptors specification, from memory I am pretty sure the base class method is mean't to be called first, but the spec gives you the full order.



@Inject methods are called before @PostConstuct (the are called in InjectionTarget.inject, which gets called before InjectionTarget.postConstruct).



I don't think we specify an order for @Inject methods.



Stuart



On 01/10/2011, at 5:47 AM, Mark Struberg wrote:



> Hi!

>

> JSR-250 common annotations is pretty thin about having @PostConstruct in multiple class hierarchies. It just says that there must only be one single method annotated with @PostConstruct in a class. Thus my question:

>

> If I have

>

>

> public class Animal {

>  @PostConstruct

>

>  public void doInit() {..}

>  ..

>

> }

>

> and

>

>  public class Horse extends Animal {

>  @PostConstruct

>

>  public void doSomeOtherInit() {..}

>  ..

>

> }

>

>

> 1.) for a contextual instance of Horse, will Animal#doInit() get executed or only the one from the 'effective' class?

> 2.) if 1.) was yes, then In which order do they get executed? Is this specced somewhere?

>

> 3.) Same scenario with @Inject methods. Do we specify an order?

>

> 4.) Both classes have @Inject methods and @PostConstruct. Again: which order of invocaition?

>

>

> Just that you understand my intention: we had a @PostConstruct method in Horse which did set a 'cached' flag in Animal. Turned out that this was a random generator depending on the intsalled server ;)

>

>

> LieGrue,

> strub

>

> _______________________________________________

> cdi-dev mailing list

> [hidden email]

> https://lists.jboss.org/mailman/listinfo/cdi-dev





_______________________________________________

cdi-dev mailing list

[hidden email]

https://lists.jboss.org/mailman/listinfo/cdi-dev


 


_______________________________________________
cdi-dev mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/cdi-dev