• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using @PostConstruct in an abstract class

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. Is it possible to use @PostConstruct annotation on a non-abstract method of an abstract class? In our application the annotation works perfectly if is placed on a method of a managed bean. But it doesn't work if I pull it up in the class hierarchy. For example:



In this example method AbstractParentBean.init() is not invoked despite the fact it is marked with @PostConstruct. Is it incorrect to put @PostConstruct annotation on a parent class (abstract or non-abstract)?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@PostConstruct will only work when the object is being managed by the container.

If a class isn't being managed, there isn't really a need for @PostConstruct, since there are no properties being set after construction, and what-not.

~Zack
 
Denis Zjukow
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Zack, thanks for reply. The thing is that in my example class MyBean is managed by the container. And so is AbstractParentBean, as it is a "part" of MyBean. So I don't understand why the container doesn't call the init() method. In my opinion, there is no reason not to call it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic