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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:45:41+00:00 2026-05-19T17:45:41+00:00

I am new to Spring DI and i am implimenting DI for the first

  • 0

I am new to Spring DI and i am implimenting DI for the first time in my webapplication.
it seems i am doing somehing wrong and it related the way i am using spring scope.here is my problem
i have a serive class where i am injecting various other object in order to achieve the desired functionality
here is my spring file entries

<bean id="ImportServiceImpl" class="ImportServiceImpl" factory-method="getInstance">
        <property name="browseDirectory" ref="browseDirectoryImpl"/>
        <property name="xmlUnmarshaller" ref="xmlUnmarshallerImpl"/>
        <property name="Adaptar" ref="AdaptarImpl"/>
        <property name="DAOService" ref="DAO"/>
     </bean>

     <bean id="browseDirectoryImpl" class="BrowseDirectoryImpl" factory-method="getInstance" />
     <bean id="xmlUnmarshallerImpl" class="XMLUnmarshallerImpl"/>
     <bean id="AdaptarImpl" class="AdaptarImpl" factory-method="getInstance"/>

now in my adaptarImpl class i have a refrence to some other object which is being initialized in the constructor

private AdaptarImpl(){
    foo=new Foo();
}

now for the first time when the server start and this service run fist time everything is fine foo is being initilized to its proper initialization value but for all other subsequent calls Spring is returing refrence to the previous initialized foo object where i want that for each new request a new instance of foo should be created.
it apperas to me that the factory method being used in the above code factory-method="getInstance"
is being called only once when server called and all other subsequent calles returning same refrence where i want a new instance for every request.
here is my facory method

public static ImportServiceImpl getInstance(){
    return new ImportServiceImpl();
}

i know i am doing basics wrong in DI but not sure where it is.I am using Struts2 for MVC and for service layer using Spring DI
any help in this regard will be helpful

Thanks
Umesh

  • 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-19T17:45:41+00:00Added an answer on May 19, 2026 at 5:45 pm

    I’m not sure I understand your question, but it sounds like you ought to ask Spring to inject the reference to Foo into your AdapterImpl and make its scope “request”. If you need Spring to control object creation, don’t call “new”.

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

Sidebar

Related Questions

I'm new to spring controllers using annotated controllers. Here is my configuration Bean definition
I am new to spring and I am currently using ClassPathXmlApplicationContext to getBean inside
This is the first time i'm asking a question here at stack overflow so
New to Spring-MVC. I want to store two properties (uploadFolder=.., downloadFolder=..) in a .properties
I m very new in spring batch project.I m trying to create a project
I'm new to Spring Security. How do I add an event listener which will
I am new to Spring MVC. But I had certain experience in working with
I am new to Spring Security. I have been working on creating a custom
I'm new to Spring and trying to use the Spring Formatting SPI for UI
i AM NEW TO Spring Framework . Can any body explain me difference between

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.