Rafał Krupiński wrote:
On 21.01.2010 16:40, Emi Lu wrote:
Good morning,
Could someone tell me where to put bean.xml (spring configuration)? It
is not shown in the following document
http://www.vaannila.com/spring/spring-ioc-1.html
Thanks a lot!
The proper place for spring beans declaration in webapp is
/WEB-INF/aplicationContext.xml
but this article doesn't mention how to load this file, so better for
you to read spring documentation.
At least that part on integration with struts.
Thank you.
Ok, here is my solution for now:
(1) web.xml
<!-- Uncomment/comment this if you need/don't need Spring support -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
(2) ApplicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="springQuizMaster"
class="example.action.spring.SpringQuizMaster"> </bean>
<bean id="strutsQuizMaster"
class="example.action.spring.StrutsQuizMaster"> </bean>
<bean id="quizMasterService"
class="example.action.spring.QuizMasterService">
<property name="quizMaster" ref="springQuizMaster" />
</bean>
<bean id="processSpring1" class="example.action.spring.ProcessSpring1">
<property name="quizMasterService" ref="quizMasterService" />
</bean>
</beans>
(3) ProcessSpring1.java
public class ProcessSpring1 extends ActionSupport
{
private QuizMasterService quizMasterService ;
private String str_result ;
public String execute()
{
System.out.println(quizMasterService.getQuizMaster().popQuestion());
this.setStr_result(quizMasterService.getQuizMaster().popQuestion());
return SUCCESS;
}
public QuizMasterService getQuizMasterService()
{
return quizMasterService;
}
public void setQuizMasterService(QuizMasterService quizMasterService)
{
this.quizMasterService = quizMasterService;
}
public String getStr_result() {
return str_result;
}
public void setStr_result(String str_result) {
this.str_result = str_result;
}
}
(4) struts.xml
<action name="ProcessSpring1"
class="example.action.spring.ProcessSpring1">
<result name="success">/WEB-INF/pages/spring/spring1.jsp</result>
</action>
(5) spring1.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<Center> <B>Spring Examples1</B></Center>
<HR>
<BR/>
<B>Spring result</B>: <s:property value="str_result" /> <BR/>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org