简体   繁体   中英

@PostConstruct dont call in a session managed bean

Like I say in the title, I have a method with the @PostConstruct tag in a managed bean in session scope. But the method is never called. In another bean in view scope the @PostConstruct works fine. The @Postconstruct tag work in a session bean? That's basically my question. Bye and thanks!

I was also facing the same issue. The issue get resolved when I destroy the bean from the session(if the bean is in the session scope, it works fine for request scope). When the bean is in the session scope, the method with the @PostConstruct annotation will never be called twice, as the bean has already been instantiated and is stored in the session.

Make sure you don't have a @PostConstruct on any other method in your bean or your bean's predecessor. There is only one @PostConstruct allowed for a managed bean.

How do you refer the session bean? Maybe the bean was not instantiated yet, do you also have some logging in the constructor of the managed bean?

Also, the constructor is never called, but the bean work just fine, except the @postconstruct method and constructor not called

Either you have not compiled and deployed the bean class with the changes, or you have another copy of the bean with the same name but in a different package which in turn is actually been used instead.

Verify everything, cleanup everything and do a full rebuild/redeploy/restart.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM