RequestScoped

@RequestScoped
public class RequestScopedClass {
    //This class gets constructed once per Servlet request, and is shared among all CDI-managed classes within that request.

    @Inject
    public RequestScopedClass(SomeDependency someDependency) {
        doSomethingWith(someDependency);
    }

    public RequestScopedClass() {
        //Note that it is required that a request scoped class have a public no-args constructor
    }

}

如果 bean 使用 @RequestScoped 進行註釋,則會為任何請求建立一次。如果兩個物件依賴於請求範圍類,則它們都將獲得對同一物件的引用。

注意: 任何請求範圍的 bean 必須具有公共的無引數建構函式。其原因將在後面解釋。