java 從零開始,學習筆記之基礎入門(四十一)

Struts-Spring

Struts-Spring整合配置圖

 


Spring配置文件

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"

    xmlns:p="http://www.springframework.org/schema/p"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

 

    <import resource="applicationContext-dao.xml"/>

 

    <import resource="applicationContext-service.xml"/>

   

    <import resource="applicationContext-action.xml"/>

 

</beans>

 

applicationContext-action.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.5.xsd">

 

    <bean name="groupmaction" class="com.softeem.action.GroupManagerAction">

         <property name="service" ref="gservice">

         </property>

    </bean>

</beans>

 

applicationContext-service.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.5.xsd">

 

    <bean name="gservice" class="com.softeem.service.impservice.GroupService">

         <property name="dao" ref="groopservice">

         </property>

    </bean>

</beans>

 

applicationContext-dao.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"

    xmlns:p="http://www.springframework.org/schema/p"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

 

    <bean name="groopservice" init-method="init" destroy-method="destroy" class="com.softeem.dao.impdao.GroupDAO" scope="prototype">

       <property name="name" value="產品研發組">

       </property>

      

       <constructor-arg type="int" value="1000"></constructor-arg>

    </bean>

 

</beans>

 

Struts配置文件

Struts.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <package name="group" extends="struts-default">

       <action name="groupadd" class="groupmaction">

           <result name="success">success.jsp</result>

       </action>

    </package>

</struts>

 

Struts.properties

struts.action.extension=do

 

struts.objectFactory=spring

 

struts.objectFactory.spring.autowire=name

 

整合需導入的插件包

 

Web.xml配置文件

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5"

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

 

  <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath*:applicationContext-*.xml</param-value>

  </context-param>

 

  <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

  </listener>

 

  <filter>

    <filter-name>filterDispatcher</filter-name>

    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

  </filter>

 

  <filter-mapping>

    <filter-name>filterDispatcher</filter-name>

    <url-pattern>/*</url-pattern>

  </filter-mapping>

</web-app>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章