Search code examples
jsfcdimanaged-bean

Is there any harm in using Inject annotation in a JSF Managed Bean?


@Inject annotation works just fine in a @ManagedBean. ( as long as you have a beans.xml in classpath ) Is there any harm in this?


Solution

  • @Inject is a Java CDI annotation. There's no problem in using it while you have the proper context (you need a CDI container context prepared by yourself or a JavaEE application server).

    If you migrate your application to a servlet container like Tomcat, you need to manage the context by yourself (as it is not considered a JavaEE AS) or you could replace the annotation by @ManagedBean, but you'll be able only to inject JSF managed beans and not every single Java Bean.