Struts2 Spring3 Mybatis 3 整合 相关配置文件

SpringContext.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:context = "http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<!-- 根据通用占位符设置数据库连接 -->
 <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${driver}" />
    <property name="url" value="${url}" />
    <property name="username" value="${username}" />
    <property name="password" value="${password}" />
</bean>
 <!-- 导入属性占位符所在文件 --><context:property-placeholder location="classpath:resources/jdbc.properties"/>
<!--annotation 驱动事物管理 -->

<tx:annotation-driven transaction-manager="transactionManager" />
 
<!--事物管理bean -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>
 
<!--创建sqlsessionFactory bean并引入mybatis配置文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:resources/mybatis-config.xml"/>
</bean>
 

<!--供DAO类试用的数据操作bean -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">  
    <constructor-arg index="0" ref="sqlSessionFactory"/>  
</bean>

<!--定时器 -->
<task:scheduler id="schedulerManager" pool-size="20" /> 

<!--导入外部Spring文件 -->

<import resource="spring-kk.xml"></import></beans>





struts2.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>
    <!-- constant name="struts.locale" value="en_US"></constant>  -->
    <constant name="struts.locale" value="zh_CN"></constant>
    
    <constant name="struts.i118n.encoding" value="UTF-8"></constant>
    <constant name="struts.objectFactory" value="spring"></constant>
    <constant name="struts.custom.i18n.resources" value="commResources" />
    
    
    <package name="项目-default" namespace="/" extends="struts-default">
        <global-results>
            <result name="defaultException">/路径/defaultException.jsp</result>
        </global-results>
        
        <global-exception-mappings>
            <exception-mapping result="defaultException" exception="java.lang.Exception"></exception-mapping>
        </global-exception-mappings>

    </package>
<!--导入各模块的struts2.xml文件-->
 <include file="路径/resources/struts-模块.xml"/>
    

</struts>



jdbc.properties文件


dbtype=firebird
driver=org.firebirdsql.jdbc.FBDriver
url=jdbc:firebirdsql:localhost/3050:D:/Firebird/data/db.FDB
username=root
password=root



web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>com.fnic.cdnmgr.ui</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
      <filter-name>Struts2</filter-name>
      <filter-class>
           org.apache.struts2.dispatcher.FilterDispatcher
      </filter-class>
  </filter>
  
  <filter-mapping>
      <filter-name>Struts2</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <context-param> 
      <param-name>webAppRootKey</param-name> 
      <param-value>cdnmgr.root</param-value> 
  </context-param> 
  
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springContext.xml</param-value>
  </context-param>
  
  <context-param>
       <param-name>log4jConfigLocation</param-name>
       <param-value>classpath:log4j.properties</param-value>
  </context-param>
  
  <context-param>
      <param-name>log4jRefreshInterval</param-name>
      <param-value>3000</param-value>
  </context-param>
  
<filter>
       <filter-name>SessionFilter</filter-name>
       <filter-class>
             路径.filter.SessionFilter
       </filter-class>
    	<init-param>
              <param-name>avoid-urls</param-name>
              <param-value>login.jsp,login.action,.png,.css,.js,.jpg</param-value>
       </init-param>
  </filter>

  <filter-mapping>
       <filter-name>SessionFilter</filter-name>
       <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <listener>
       <listener-class>路径.项目ContextLoaderListener</listener-class>
  </listener>
  
  <listener> 
       <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
  </listener> 
  
  <welcome-file-list>
        <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  
  <session-config>
  	<session-timeout>60</session-timeout>
  </session-config>
  
    <error-page>
  <error-code>404</error-code>
	<location>/cdn/404error.jsp</location>
	</error-page>
	<!--  
    <error-page>
  	<error-code>500</error-code>
	<location>/cdn/500error.jsp</location>
  </error-page>
  -->
</web-app>


mybatis-config.xml


<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">  
<configuration>  
    <properties resource="resources/jdbc.properties" />
<!--映射数据操作文件  多种匹配方案  根据数据库设置鉴定使用哪种数据 并且同时映射出不同的相关sql文件-->
    <mappers>  
        <mapper resource="m/dao/sql/${dbtype}/sqlmapper.xml" />
        <mapper resource="a/dao/sql/${dbtype}/sqlmapper.xml" />
        <mapper resource="b/dao/sql/${dbtype}/sqlmapper.xml" />
        <mapper resource="s/topo/dao/sql/${dbtype}/sqlmapper.xml" />
    </mappers>

</configuration>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值