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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:47:24+00:00 2026-05-24T11:47:24+00:00

I have next situation: Connection manager should have each time one object of ConnectionServer

  • 0

I have next situation:
Connection manager should have each time one object of ConnectionServer and new objects of DataBean
So, I have created these beans and configured out it spring xml.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="dataBena" class="com.test.DataBean" scope="prototype"/>
    <bean id="servCon" class="com.test.ServerCon"/>
    <!--<bean id="test" class="com.test.Test"/>-->
     <context:component-scan base-package="com.test"/>
</beans>

and added scope prototype for DataBean

After this I’ve created simple util/component class called Test

@Component
public class Test {

    @Autowired
    private DataBean bean;
    @Autowired
    private ServerCon server;

    public DataBean getBean() {
        return bean.clone();
    }

    public ServerCon getServer() {
        return server;
    }

}

BUT, Each time of calling getBean() method I am cloning this bean, and this is the problem to me.
Can I do it from spring configuration without usning clone method?
Thanks.

  • 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-24T11:47:25+00:00Added an answer on May 24, 2026 at 11:47 am

    You are looking for lookup method functionality in Spring. The idea is that you provide an abstract method like this:

    @Component
    public abstract class Test {
      public abstract DataBean getBean();
    }
    

    And tell Spring that it should implement it at runtime:

    <bean id="test" class="com.test.Test">
      <lookup-method name="getBean" bean="dataBean"/>
    </bean>
    

    Now every time you call Test.getBean you will actually call Spring-generated method. This method will ask ApplicationContext for DataBean instance. If this bean is prototype-scoped, you will get new instance each time you call it.

    I wrote about this feature here.

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

Sidebar

Related Questions

I have next situation: 1) N workers, all workers do same things 2) Each
I have next situation: I should allow to see Add Rendering button in Page
I have the next very strange situation and problem: .NET 4.0 application for diagram
I have next 2 blocks of code: def replace_re(text): start = time.time() new_text =
I use symfony 1.4.10 I have next situation: User can create Ads and he
I have a situation where in MS Dynamics Crm it returns some objects using
I am searching for some help in next situation: I have some class and
I have a situation like this I want to add a UILabel next to
I have a situation where I need to use jQuery's $.fn.one() function for a
I need develop next situation: i have main_screen.xml with TabHost, wich have two (or

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.