You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Emi Lu <em...@encs.concordia.ca> on 2010/01/21 16:40:41 UTC

Where to put bean.xml (spring configuration)?

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!
--
Lu Ying



bean.xml
=================
01.<?xml version="1.0" encoding="UTF-8"?>
02.<beans xmlns="http://www.springframework.org/schema/beans"
03.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
04.xsi:schemaLocation=" http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd">
05.
06. <bean id="springQuizMaster" 
class="com.vaannila.SpringQuizMaster"></bean>
07.    <bean id="strutsQuizMaster" 
class="com.vaannila.StrutsQuizMaster"></bean>

08.    <bean id="quizMasterService" class="com.vaannila.QuizMasterService">

09.        <property name="quizMaster">

10.        <ref local="springQuizMaster"/>
11.        </property>
12.    </bean>
13.
14.</beans>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Where to put bean.xml (spring configuration)?

Posted by Emi Lu <em...@encs.concordia.ca>.
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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Where to put bean.xml (spring configuration)?

Posted by Rafał Krupiński <r....@gmail.com>.
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.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org