Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:39:58+00:00 2026-05-27T20:39:58+00:00

I am trying to inject an Interceptor with a Vaadin Application instance created by

  • 0

I am trying to inject an Interceptor with a Vaadin Application instance created by Guice.
I’ve followed the documentation for Vaadin-Guice integration in the Vaadin Wiki and
the documenation on Interceptor DI in the Guice Wiki:

public class RecruitmentServletConfig extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {

        ServletModule servletModule = new ServletModule() {

            @Override
            protected void configureServlets() {
                ...
                bind(Application.class).to(RecruitmentApplication.class).in(ServletScopes.SESSION);
                SecurityGuard securityGuard = new SecurityGuard();
                requestInjection(securityGuard);
                bindInterceptor(Matchers.subclassesOf(CustomComponent.class), Matchers.annotatedWith(AllowedRoles.class), securityGuard);
            }
        };
        return Guice.createInjector(servletModule);
    }
}

The SecurityGuard interceptor:

public class SecurityGuard implements MethodInterceptor {
    @Inject private Application application;

    public Object invoke(MethodInvocation invocation) throws Throwable {
        AllowedRoles allowedRoles = invocation.getMethod().getAnnotation(AllowedRoles.class);
        if (((User) application.getUser()).hasRole(allowedRoles.value())) {
            return invocation.proceed(); 
        } else {
            return null;
        }
}

However, I get an OutOfScopeException on server startup:

SEVERE: Exception sending context initialized event to listener instance of class de.embl.eicat.recruit.ioc.RecruitmentServletConfig
com.google.inject.CreationException: Guice creation errors:
1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped object. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
at recruit.ioc.RecruitmentServletConfig$1.configureServlets(RecruitmentServletConfig.java:86)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:39:59+00:00Added an answer on May 27, 2026 at 8:39 pm

    Does it work if you wrap your Application in a Provider?

    public class SecurityGuard implements MethodInterceptor {
        @Inject private Provider<Application> application;
    
        public Object invoke(MethodInvocation invocation) throws Throwable {
           AllowedRoles allowedRoles = invocation.getMethod().getAnnotation(AllowedRoles.class);
            if (((User) application.get().getUser()).hasRole(allowedRoles.value())) {
                return invocation.proceed(); 
            } else {
                return null;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
i'm trying to inject stuff into a custom ViewPage (ModelViewPage, from MvcContrib) public class
I'm trying to inject EntityManager in my DAO using EJB @Entity public class Book
I'm trying to use Google Guice with the @Inject and @Singleton properties as follows:
I'm trying to inject a portletrequest in my aspect class @Autowired(required = true) private
I'm trying to use Spring to inject a SLF4J logger into a class like
I'm working on an application using ASP.NET MVC 1.0 and I'm trying to inject
I'm trying to inject an asp.net classic web control to my asp.net mvc application.
I am trying to inject entity manager in some helper class, I can pass
I'm trying to inject Spring beans into an EJB using @Interceptors(SpringBeanAutowiringInterceptor.class) but I cannot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.