This is my eventAction ActionSupport Class
public class EventAction extends ActionSupport {
protected EventService eventService;
protected String redirectUrl;
public String getRedirectUrl() {
return redirectUrl;
}
public void setRedirectUrl(String redirectUrl) {
this.redirectUrl = redirectUrl;
}
public void setEventService(EventService services) {
this.eventService = services;
}
}
And here is a fragment from my applicationContext.xml
<bean id ="eventService" class ="services.EventService" scope ="singleton">
<property name = "sessionFactory" ref = "sessionFactory"/>
</bean>
The code is working fine except for when I change the id inside the declartion.
My question why does spring <bean id ="eventService"> id has to be matched with eventService instance variable inside EventAction support class? isn’t id is just making an identifier for the bean that is going to be created? why should the id inside the bean tag should be the same inside my EventAction, where the EventAction class is not even being mentioned in the configruation?
From Spring docs beans-beanname
I believe for Spring-Struts2 you are using the plugin where you need to either define auto-wire strategy or plugin will use default one which is
name.That means when plugin bridge between Struts2 and Spring it will try to inject beans based on the supplied auto-wire strategy
Refer to Struts2 Spring-plugin