2、要用到SRPING的东西,就是必须加载SPRING的配置文件(applicationContext.xml),在这里我们通过服务启动时去加载,所以要配置修改web.xml文件。在原来的基础上添加以下配置:
- <!---这个就是用来加载SPRING配置文件的---->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- /WEB-INF/classes/applicationContext.xml
- </param-value>
- </context-param>
- <listener>
- <listener-class>
- org.springframework.web.context.ContextLoaderListener
- </listener-class>
- </listener>
- <!---这个是DWR本身的配置--->
- <servlet>
- <servlet-name>dwr</servlet-name>
- <servlet-class>
- org.directwebremoting.servlet.DwrServlet
- </servlet-class>
- <init-param>
- <param-name>debug</param-name>
- <param-value>true</param-value>
- </init-param>
- </servlet>
- <servlet-mapping>
- <servlet-name>dwr</servlet-name>
- <url-pattern>/dwr/*</url-pattern>
- </servlet-mapping>
<!--- 这个就是用来加载SPRING配置文件的----> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/classes/applicationContext.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!--- 这个是DWR本身的配置---> <servlet> <servlet-name>dwr</servlet-name> <servlet-class> org.directwebremoting.servlet.DwrServlet </servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping>
3、SPRING 的配置不变,一样给业务类注入DAO对象
- <beanid="bidbiz"class="com.byz.bizimpl.BidImpl">
- <propertyname="biddao">
- <reflocal="BidDAO"/>
- </property>
- <propertyname="goodsdao">
- <reflocal="GoodsDAO"/>
- </property>
- <propertyname="userdao">
- <reflocal="UsersDAO"/>
- </property>
- </bean>
<bean id="bidbiz" class="com.byz.bizimpl.BidImpl"> <property name="biddao"> <ref local="BidDAO"/> </property> <property name="goodsdao"> <ref local="GoodsDAO" /> </property> <property name="userdao"> <ref local="UsersDAO" /> </property> </bean>
4、DWR配置文件配置,这时我们需要将原先的creator="new" DWR去实例对象的,现在要改为creator="spring" 由spring注入进来。 Dwr这有个参数 <param name="beanName" value="spring对象"/> 这个可以将对象接收到。
- <?xmlversion="1.0"encoding="UTF-8"?>
- <!DOCTYPEdwrPUBLIC"-//GetAheadLimited//DTDDirectWebRemoting2.0//EN""http://getahead.org/dwr/dwr20.dtd">
- <dwr>
- <allow>
- <createjavascript="BidImpl"creator="spring"
- scope="application">
- <!--<paramname="class"value="com.byz.bizimpl.BidImpl"/>-->
- <!--将Spring中的对象给到参数-->
- <paramname="beanName"value="bidbiz"/>
- <includemethod="add"/>
- </create>
- </allow>
- <!--参数集合配置-->
- <signatures>
- <![CDATA[
- importjava.util.List;
- com.byz.bizimpl.BidImpl;
- BidImpl.add(List);
- ]]>
- </signatures>
- </dwr>