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

  • Home
  • SEARCH
  • 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 8885701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:22:27+00:00 2026-06-14T21:22:27+00:00

Well, I have 3 layers from Controller->Service->Repository made in MVC Spring 3 design. Now,

  • 0

Well, I have 3 layers from Controller->Service->Repository made in MVC Spring 3 design. Now, my question is, since the default scope is defined as Singleton, are they thread-safe?

Here is the code look like:

UserController.java

@Controller
@RequestMapping("/users")
public class UserController extends ExceptionExtension {
     @Autowired
     private IUserService userService;

     @RequestMapping(value = { "/update", "/update/" }, method = RequestMethod.GET)
     public String updateUser(@RequestParam("email") String eMail, ModelMap model)
        throws Exception {

          if (eMail.isEmpty() || eMail == null) {
              throw new ArgumentIsEmptyException("Required String parameter 'email' is empty");
          } else {
              UserModel userModel = userService.setUser(eMail);

              if (userModel != null) {
                  model.put("roleList", userService.setRoleList());
                  model.put("title", "Update Existing User");
                  model.put("post", "/users/post/update");
                  model.put("userForm", userModel);

                  return "users.update";
              } else {
                  model.put("title", "Update Existing User");
                  model.put("result", "<font color='red'><u>" + eMail + "</u> does not exist in the database.</font>");
                  model.put("flag", "Error");

                  return "users.result";
              }
          }
     }
}

UserService.java

public class UserService implements IUserService {

    @Autowired
    private IUserManager userManager;

    public UserModel setUser(String eMail) {
        UserModel userModel = new UserModel();
        Entity userEntity = userManager.getUser(eMail);

        if (userEntity != null) {
            userModel.setEMail(eMail);
            userModel.setRole(userEntity.getProperty("role").toString());
            userModel.setEnable((Boolean)userEntity.getProperty("enable"));

            return userModel;
        } else {
            return null;
        }
    }
}

Say, User A and User B are concurrently running the same url but different parameter.

User A request => “http://domain.com/users/update?user=myname1@domain.com&#8221;.
User B request => “http://domain.com/users/update?user=myname2@domain.com&#8221;.

Since the Controller is singleton, will the User A eMail variable overlaps to the User B one and the vice versa?

I am finding hard to understand on how is the Singleton Thread-Safe working in this scenario. Should my @Service and @Repository declare as @Scope(“prototype) so the inner method variables are isolated from new instantiate?

====>

with Scope(“request”) to my @Service layer, I hitted this error message :/

3328 [main] ERROR org.springframework.web.context.ContextLoader –
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘roleController’: Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private com.company.dashboard.service.IRoleService
com.company.dashboard.controller.RoleController.roleService; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘roleService’: Scope ‘request’ is not
active for the current thread; consider defining a scoped proxy for
this bean if you intend to refer to it from a singleton; nested
exception is java.lang.IllegalStateException: No thread-bound request
found: Are you referring to request attributes outside of an actual
web request, or processing a request outside of the originally
receiving thread? If you are actually operating within a web request
and still receive this message, your code is probably running outside
of DispatcherServlet/DispatcherPortlet: In this case, use
RequestContextListener or RequestContextFilter to expose the current
request.

  • 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-06-14T21:22:29+00:00Added an answer on June 14, 2026 at 9:22 pm

    Here Thread Safety depends upon the internal locking of userService in case of scope singleton

    This is what ultimately happens => The same userSpace bean is used for both the requests and both requests concurrently access userService bean. So the IUserService needs to be thread safe for the whole operation to perform well.

    Or

    put the scope to request.

    In which case a new bean is allocated for every request and the whole operation is thread-safe, thanks to thread confinement. Provided you code accordingly in IUserSpace

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

Sidebar

Related Questions

Well i have a web page hosted in a IIS 7.0 now the problem
Well I have been writing in the same style for awhile now and all
We have a decent sized MVC project running well at the moment, i've started
From inside to outside, these are our MVC app layers: MS SQL / Tables
I have been working with ASP.NET MVC for a couple of months now and
Like in most spring+hibernate enterprise cases, I want to separate Dao, Service, Web layers
We are seeing Spring in school right now but we don't have the time
well i have a configuration like this in the components part of my config
Well i have a div tag that i show as a modal dialog this
well I have that problem, im using a lightbox srcipt and im opening an

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.