Search code examples
jsfjakarta-eecdi

@SessionScoped cannot be resolved to a type


I am using @SessionScoped in my managed bean and it gives me the error.

@SessionScoped cannot be resolved to a type

What am I missing?

Relevant code:

package javaeetutorial.guessnumber;

import java.io.Serializable;
import java.util.Random;

@Named
@SessionScoped
public class UserNumberBean implements Serializable {
    // Do stuff.
}

Solution

  • Add the import below,

    import javax.enterprise.context.RequestScoped;
    

    In the future your can always use you IDE to resolve the imports for you, ctrl+shift+o in eclipse.

    Hope that helps.