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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:55:50+00:00 2026-06-13T01:55:50+00:00

I have one small issue with creating a new bean. Basically as per request,

  • 0

I have one small issue with creating a new bean. Basically as per request, I get some parameters, which needs to be passed to a bean. Below I am instantiating ControllerService for each request. Rather I would like it to be a bean with scope=protype. So that I get a fresh object for every request.
But then how do i set the 2 properties (kpiName, kpiInput) that I am sending via constructors in the bean??

@Autowired
@Qualifier("serviceManager")
Cleanser serviceManager;  

@RequestMapping(method = RequestMethod.POST)
public @ResponseBody
String getKPIResult(@RequestParam("kpiName") String kpiName,
            @RequestParam("kpiInput") String kpiInput) {    

    return serviceManager.checkAndExecute(new ControllerService(kpiName, kpiInput));
}
  • 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-13T01:55:51+00:00Added an answer on June 13, 2026 at 1:55 am

    In situations like this where you’re going against the grain of Spring, I’d suggest that perhaps you’re doing something in a way that’s not considered best practice. Without more context it’s hard to see though.

    Spring Social uses a request scope bean to embody a repository for a specific user. I’ve now idea why as it’s a horribly inefficient way of doing things, and much less understandable IMHO.

    <bean id="connectionRepository" factory-method="createConnectionRepository"
        factory-bean="usersConnectionRepository" scope="request">
        <constructor-arg
            value="#{T(org.springframework.security.core.context.SecurityContextHolder).getContext().getAuthentication().getPrincipal()}" />
        <aop:scoped-proxy proxy-target-class="false" />
    </bean>
    

    You can see here the use of factory-bean and factory-method to declare a class/method to call when wanting an instance of your class. The constructor argument is passed using SpEL. I’m not quite sure how you’d achieve this with Spring MVC responding to web requests, but I’m fairly sure you could use Spring Integration to pass a message and use SpEL to grab headers/payload form that message to pass to the constructor.

    Again though, I’d really question your design pattern here – a more usual SOA idiom is to create services on startup, and have them as stateless as possible from there-on in, rather than create an instance with specific state for each request. Best of luck!

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

Sidebar

Related Questions

Hi i have a small query which takes data from one mysql database and
Hi guys! Hope somebody could help me to solve one small issue. I have
I have a small issue. I am trying to pull some data from my
I have a small issue with a CA2000 warning. In my project which is
I have one small, but frustrating issue. I create installer with possibility for shortcut
We're having a small issue and could use some help - we have the
I'm quite new to ThreeJS and I have a small issue (probably wrong usage).
I have one small online sale business but I want to make it scalable
Post-release, I have made one small change to one form in our development site
I am using asp.net .. i have created one small application.. I have Configure

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.