您的位置:首页 > 编程语言 > Java开发

java 从零开始,学习笔记之基础入门<Struts2_Spring_整合>(四十一)

2014-02-19 09:43 1101 查看
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>
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐