The following are some potential errors that you can make using CDI managed beans. These errors all have symptoms that are difficult to debug so you need to make manual checks to make sure they are not causing problems.

The newer @Named annotation puts beans under CDI management. The CDI management is essential for using injection. It also simplifies several aspects of developing web applications.

The @ManagedBean annotation is an older form of bean class annotation. Although most of the things that can be done with the @Named annotation can also be done with the @ManagedBean annotation, doing so requires more entries in the faces-config.xml and other configuration files.

For scope annotations on CDI managed beans, the imports should be from the javax.enterprise.context package. When you create a JSF web application project, one of the dialogs (the "Server and Settings" dialog) has a checkbox labeled "Enable Contexts and Dependency Injection". If this is checked then when you use the NetBeans "Fix Imports" facility it will offer the correct imports as the defaults. Otherwise you may get the defaults appropriate for the @ManagedBean annotation - these defaults will not work with CDI managed beans.

The GlassFish web server will refuse to deploy a JSF application if any of its managed beans (including CDI managed beans) have public instance variables. The best practice is to declare all instance variables private for any kind of bean. Bean properties can be accessed through public getters and setters.

NetBeans gives a warning about invoking a bean's public method inside its constructor. Doing this may also cause problems in a GlassFish web application due to the fact that the server creates subclasses your bean classes and uses the subclass instances instead of your classes.

You could eliminate the NetBeans warning by declaring the method as final. Do not do this. The GlassFish web server will refuse to deploy a JSF application if any of its managed beans (including CDI managed beans) have public methods that are declared final.

If you want to use a public method inside a bean constructor the best practice is to declare two methods, one public and one private. The private method should have slightly different name but the same parameters. Move all of the code to the private method. The public method just invokes the private one. Then use the private method in the constructor.

Two simple rules apply to the use of injected variables. Suppose you have declare such a variable as follows:

private Database database;