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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:32:02+00:00 2026-05-23T11:32:02+00:00

I am developing a small application with Struts2 + Spring + hibernate…Spring beans are

  • 0

I am developing a small application with Struts2 + Spring + hibernate…Spring beans are injected properly on server start-up .. I have stepped through the setters on start up and they are injecting properly. However, I run the post method and then the post method(execute() in struts2) and the values that were injected are null. Why does this happen?

Bean injection is :

<bean id="userAction" class="com.example.user.action.UserAction">
      <constructor-arg  index="0">
            <ref bean="UserServiceTarget"/>
      </constructor-arg>
</bean>

My Struts2 constructor is :

 public UserAction(IUserService userService) 
   {
       this.userService=userService; 

   } 

Struts2 method is :

 public String execute() { 
       this.user=(User)userService.findById(this.id); 
}

But inside execute method userService value is null… When i inject they are injected prperly..

Thank you…

  • 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-23T11:32:03+00:00Added an answer on May 23, 2026 at 11:32 am

    I think constructor-args are not the way to ijecting beans to another. I give you an example:

    applicationContext.xml:

    <bean id="userAction" class="com.example.user.action.UserAction"/>
    <bean id="userServiceTarget" class="com.example.user.UserServiceTarget">
    

    UserAction.java:

    @Autowired
    private UserServiceTarget userService;
    

    You can use other configurations also.
    For example:

    <bean id="userAction" class="com.example.user.action.UserAction">
    <property name="userService" ref="UserServiceTarget"/>
    </bean>
    

    By this way the Autowired annotation not needed, only a setter.

    I don’t like xml so much, so the best way is to using Stereotype annotations. You can use @Service annotation on your service class and you can forget to declare the bean in the appcontext, but you should add two lines this way:

    <context:annotation-config />
    
    <context:component-scan base-package="com.example"/>
    

    Hope I helped!

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

Sidebar

Related Questions

I'm developing a small application using Blend, basically what I have in my application
I have question I'm developing small application to desktop in win Forms. I'm using
I'm new to objective-c and at the moment developing a small application. I have
I am developing a small application in android in which i have few image
I am developing a small intranet based web application. I have YSlow installed and
I'm developing a small application with C# in .NET and I want to have
I am developing a small utility application emailafriend using Spring. The basic functionality is
I am developing a small application using Struts, Spring and hibernate3. But now I
Hi here i developing small application. In a subclass screen i have two buttons.
I am developing a small application which lists the contents from files of a

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.