your web.xml seems OK
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/src/dataAccessContext.xml
/WEB-INF/src/contentContext.xml
/WEB-INF/src/scheduleContext.xml
/WEB-INF/src/securityContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoade rListener </listener-class>
</listener>
This will create a Spring webContext. So you can use it to get your beans.
ApplicationContext ctx;
String[] paths = {"dataAccessContext.xml",
"contentContext.xml",
"scheduleContext.xml",
"securityContext.xml"};
ctx = new ClassPathXmlApplicationContext(paths);
return ctx.getBean(name);
there is absolutely no need to do this because of:
1. each time this code is executed, Spring will load the xml files, parses the content and creates the beans. It will do it over and over!!!
2. you already asked spring to create the webContext that hold your beans, why not you it
please tell me what to do to let me access the beans in Strtuts Action
the easy way is to make your Actions extend
Code:
org.springframework.web.struts.ActionSupport
or
org.springframework.web.struts.DispatchActionSupport
then from your action you can access your beans using:
Code:
myBean = (MyBean) webApplicationContext.getBean("myBean");
BTW, if I am right, but why I will got two sessionFactory in one application, when I acess the OpenSessionInViewFilter, I can get a SessionFactory, but when I access the real DAOIMPL, it will use another sessionFactory, so the Session will be not find! Can anybody help me?
You have two sessionFactories because you have two contexts, one created by your listener and an other created by your code.
HTH