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 6374319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:28:23+00:00 2026-05-25T01:28:23+00:00

Is there a new instance of Spring HandlerInterceptors for each request? I have an

  • 0

Is there a new instance of Spring HandlerInterceptors for each request?

I have an interceptor in Spring, which has a class field.

public class MyInterceptor extends HandlerInterceptorAdapter {
    Private boolean state = false;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        state = true;
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        if (state == true) {
        System.out.println("Success");
        }
}

If this interceptor is used will it always print “Success”? (No matter how many threads are doing this at the same time?)

  • 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-25T01:28:24+00:00Added an answer on May 25, 2026 at 1:28 am

    How the interceptor is instantiated depends how you configiure it as a bean. If you don’t explicitly specify a scope for the bean, then it’ll be a singleton like any other bean, and so the state field will be shared by all requests.

    In this sense, interceptors are no different to controllers – be very careful about putting conversation state in them, since the objects will be shared across requests.

    if you really need a stateful interceptor and you don’t want to share the state between requests, then use a request-scoped bean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to transfer a new class instance (python class that inherits
Assume we have a simple @Configuration : @Configuration public class FooBarConfiguration { @Bean public
I have a string with the name of a class, is there a way
For instance, there is some object that will be model for strongly-typed view: class
Is there an easy way to use Spring IoC for a factory which returns
I am doing something like this: class Class(object): def __init__(self): self.var=#new instance name string#
I'm somewhat new to Spring (using 3.0), so I'm hoping there is a simple
I am quite new to Spring DI. We have two classes, PhysicalService and PhysicalDAO.
Is there a new version of XML out? If so when was it released
Does anyone know if there are new binaries for the castle logging facility using

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.