NOVOTS KMS 词汇表 Glossary    联系我们 Contact Us
查询 Search  
   
按类别浏览 Browse by Category
NOVOTS KMS .: 工作心得 .: Struts2+Spring3+MyBatis框架整合

Struts2+Spring3+MyBatis框架整合

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">
 
 <filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>struts-cleanup</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
 <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
   
 <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml
  </param-value>
 </context-param>

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

</web-app>

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:context="http://www.springframework.org/schema/context"
 xmlns:p="http://www.springframework.org/schema/p"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 <!-- 数据库连接池 -->
 <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test" />
        <property name="user" value="root" />
        <property name="password" value="root" />
        <property name="initialPoolSize" value="10" />
        <property name="minPoolSize" value="5" />
        <property name="maxPoolSize" value="30" />
        <property name="acquireIncrement" value="10" />
        <property name="maxIdleTime" value="10" />
        <property name="maxStatements" value="0" />
    </bean>
    <!-- 数据源 -->
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
      <property name="url" value="jdbc:mysql://localhost:3306/test"></property>
      <property name="username" value="root"></property>
      <property name="password" value="root"></property>
    </bean>

 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="c3p0DataSource"/>
 </bean>
 <!-- 声明式事务 -->
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 配置注解搜索的范围,该例子中spring会自动搜索org.qiuqiu下面的注解 -->
    <context:component-scan base-package="org.qiuqiu"/>
    <!-- 此处配置dao,class为一工厂类,需要注入对应的dao接口和sqlsessionfactory -->
    <bean id="personMapper" <SPAN style="COLOR: #ff0000">class="org.mybatis.spring.mapper.MapperFactoryBean</SPAN>">
  <SPAN style="COLOR: #ff0000"><property name="mapperInterface" value="org.qiuqiu.dao.PersonMapper"/></SPAN>
  <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
 </bean>

</beans>

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8" />
 <package name="json" namespace="/test" extends="struts-default">
  <action name="login" class="loginAction">
   <result name="success">/success.jsp</result>
   <result name="error">/error.jsp</result>
  </action>
 </package>
</struts>   


这篇文章对你多有用?

相关文章

article Struts2获得Session和Request对象
在Struts1.*中,要想访问request、response以及ses...

(No rating)  4-1-2012    Views: 1123   
article 如何处理Apache Struts2 远程命令执行高危漏洞和开放重定向高危漏洞
近期,CNCERT主办的国家信息安全漏洞共享平台收录...

(No rating)  8-1-2013    Views: 924   

用户评语

添加评语
当前还没有评语.


.: .: .: .: .:
[ 登陆 ]
北京护航科技有限公司 2006

Novots Technologies Limited