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

The Archive Base Latest Questions

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

I must be using @Autowired wrong, but I don’t get exactly how. This is

  • 0

I must be using @Autowired wrong, but I don’t get exactly how. This is a Spring 3.0 Portal MVC app.

The services themselves are not spring-based (they’re auto-generated). There is an impl written around the service providing some custom functionality — these classes are auto wired.

The problem I’m having is that the my autowired class appears to be treated internally as static. And therefore, this code isn’t threadsafe.

Controller class:

@Controller
@RequestMapping("VIEW")
@SessionAttributes(value={"shoppingCartCommonBean"})
public class ShoppingCartAndOrderScreenHandler     
{   
    @Autowired
    AbstractServiceImpl releaseOrderService;

    . . . 

    @ActionMapping(value = "SubmitOrder")
    public void submitOrder(Model model, PortletRequest request) {

        try {
            ReleaseOrderContract contract = new ReleaseOrderContract();

            /* Initialize contract values from request */

            releaseOrderService.setServiceRequest(contract);

            logger.debug("ReleaseOrderImpl Hash: " + 
                          releaseOrderService.hashCode());

            releaseOrderService.invoke();

         }
     . . . .
     }
 }

Where the autowiring is declared in the springconfig.xml as

<beans xmlns="http://www.springframework.org/schema/beans"  . . . >
    <context:component-scan 
        base-package="com.marchon.orderentry.shoppingcartandorder.requesthandler" />
    . . . .
    <bean class="com.marchon.orderentry.serviceimpls.ReleaseOrderServiceImpl"
          id="releaseOrderService" />
    . . . .
</beans>

I’ve seen some suspicious behavior under heavy load, where when multiple threads execute the same impl simultaneously, they don’t maintain consistent contracts (which is, yes, a non-static class variable in the service impl). And sure enough, when I print out the hashmap of the impl I get identical hashmaps — identical objects.

[ebContainer : 1] [ShoppingCartAndOrderScreenHandler . 208] DEBUG - ReleaseOrderImpl Hash: 1385321106
[ebContainer : 3] [ShoppingCartAndOrderScreenHandler . 208] DEBUG - ReleaseOrderImpl Hash: 1385321106
[ebContainer : 0] [ShoppingCartAndOrderScreenHandler . 208] DEBUG - ReleaseOrderImpl Hash: 1385321106

I would have thought that the auto-wiring would create copies of the bean for each instance of the controller class. But it’s not. What am I not understanding?

  • 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-27T09:39:03+00:00Added an answer on May 27, 2026 at 9:39 am

    Spring beans are "singleton" scope by default. If you need individual instances, "prototype":

    <bean class="com.marchon.orderentry.serviceimpls.ReleaseOrderServiceImpl"
          id="releaseOrderService"
          scope="prototype" />
    

    That it’s auto-wired isn’t relevant.

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

Sidebar

Related Questions

I've Googled for this but must be using the wrong keywords. Basically I want
I've searched for this a bit but I must be using the wrong terms
When we must use DebuggerDisplay Attributes? What is the advantage of using this?
i m using this article http://blogs.msdn.com/delay/archive/2009/09/23/if-it-walks-like-a-duck-and-talks-like-a-duck-it-must-be-a-treegrid-a-simple-xaml-only-treegrid-ui-for-wpf.aspx to have hierarchical data... i am having treeview
I've searched through the internet, I must be using the wrong keywords because I
I'm using Spring MVC 3.1.0M2 and trying to move my configs to java beans.
i am trying to use a Html.RenderPartial but getting an error: 'Using' must end
I am developing a WPF application that must run using Windows Classic theme. The
I'm using NSMapTable in a program that must run under both 3.0 and 2.2.1.
I'm using ASP.NET Roles with a special role Must Change Password. If a user

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.