1.配置web.xml,struts.xml,applicationContext.xml,jdbc.property,log4j.property的配置:
(一)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"> <display-name></display-name> <!-- 配置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> <!-- struts2配置 --> <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> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
(二)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>
<constant name="struts.locale" value="zh_CN" />
<constant name="struts.objectFactory" value="spring"></constant>
<package name="productUnit" extends="hibernate-default,json-default" namespace="/">
<!-- GoodsUnitsAction配置 -->
<action name="goodsUnitAction" class="GoodsUnitAction">
<result type="json"/>
</action>
<!--urlEdit来操作增删改一条数据 -->
<action name="editGoodsUnit" class="EditGoodUnitAction"/>
</package>
</struts>
(三)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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" 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 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"> <!-- 加载数据库配置信息 --> <context:property-placeholder location="classpath:jdbc.properties"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driverClass}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="minPoolSize" value="${cpool.minPoolSize}" /> <property name="maxPoolSize" value="${cpool.maxPoolSize}" /> <property name="maxIdleTime" value="${cpool.maxIdleTime}" /> <property name="checkoutTimeout" value="${cpool.checkoutTimeout}" /> <property name="acquireIncrement" value="${cpool.acquireIncrement}" /> <property name="initialPoolSize" value="${cpool.initialPoolSize}" /> <property name="acquireRetryAttempts" value="${cpool.acquireRetryAttempts}" /> <property name="idleConnectionTestPeriod" value="${cpool.idleConnectionTestPeriod}" /> </bean> <!-- Hibernate Session工厂配置 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.cache.use_second_level_cache">false</prop> <prop key="hibernate.jdbc.batch_size">50</prop> </props> </property> <property name="mappingResources"> <list> <value>com/newsicom/jxc/basicInfo/common/model/ProductUnits.hbm.xml</value> <value>com/newsicom/jxc/basicInfo/common/model/GoodsUnits.hbm.xml</value> </list> </property> </bean> <!-- 事务管理器配置 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- GoodsUnit --> <bean id="goodsUnitsDao" class="com.newsicom.jxc.basicInfo.goodsUnits.dao.imp.GoodsUnitsDao"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="goodsUnitsService" class="com.newsicom.jxc.basicInfo.goodsUnits.service.imp.GoodsUnitsService"> <property name="goodsUnitsDao"> <ref bean="goodsUnitsDao" /> </property> </bean> <bean id="GoodsUnitAction" class="com.newsicom.jxc.basicInfo.goodsUnits.action.GoodsUnitsAction" scope="prototype"> <property name="goodsUnitsService"> <ref bean="goodsUnitsService" /> </property> </bean> <bean id="EditGoodUnitAction" class="com.newsicom.jxc.basicInfo.goodsUnits.action.EditGoodsUnitsAction" scope="prototype"> <property name="goodsUnitsService"> <ref bean="goodsUnitsService" /> </property> </bean> </beans>
(四)jdbc.propertity的配置:
#\u6570\u636e\u5e93\u9a71\u52a8 #jdbc.driverClass=oracle.jdbc.OracleDriver #\u6570\u636e\u5e93\u8fde\u63a5 #jdbc.url=jdbc:oracle:thin:@192.168.1.24:1521:SZDB #\u767b\u9646\u5e10\u6237 #jdbc.username=testdb #jdbc.password=1qaz2wsx #\u6570\u636e\u5e93\u9a71\u52a8 jdbc.driverClass=com.mysql.jdbc.Driver #\u6570\u636e\u5e93\u8fde\u63a5 jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/CLASSICMODELS #\u767b\u9646\u5e10\u6237 jdbc.username=root jdbc.password= #\u8fde\u63a5\u6c60\u4e2d\u4fdd\u7559\u7684\u6700\u5c0f\u8fde\u63a5\u6570 cpool.minPoolSize=5 #\u8fde\u63a5\u6c60\u4e2d\u4fdd\u7559\u7684\u6700\u5927\u8fde\u63a5\u6570 cpool.maxPoolSize=100 #\u6700\u5927\u7a7a\u95f2\u65f6\u95f4\uff0c600\u79d2\u5185\u672a\u4f7f\u7528\u5219\u8fde\u63a5\u88ab\u4e22\u5f03 cpool.maxIdleTime=600 #\u5f53\u8fde\u63a5\u6c60\u7528\u5b8c\u65f6\u5ba2\u6237\u7aef\u8c03\u7528getConnection()\u540e\u7b49\u5f85\u83b7\u53d6\u65b0\u8fde\u63a5\u7684\u65f6\u95f4 cpool.checkoutTimeout=1000 #\u8fde\u63a5\u6c60\u8017\u5c3d\u7684\u65f6\u5019\u4e00\u6b21\u540c\u65f6\u83b7\u53d6\u7684\u8fde\u63a5\u6570 cpool.acquireIncrement=5 #\u521d\u59cb\u5316\u65f6\u83b7\u53d6\u7684\u8fde\u63a5\u6570\uff0c\u53d6\u503c\u5e94\u5728minPoolSize\u548cmaxPoolSize\u4e4b\u95f4 cpool.initialPoolSize=10 #\u4ece\u6570\u636e\u5e93\u83b7\u53d6\u65b0\u8fde\u63a5\u5931\u8d25\u540e\u91cd\u590d\u5c1d\u8bd5\u7684\u6b21\u6570 cpool.acquireRetryAttempts=10 #\u6bcf60\u79d2\u68c0\u67e5\u6240\u6709\u8fde\u63a5\u6c60\u4e2d\u7684\u7a7a\u95f2\u8fde\u63a5 cpool.idleConnectionTestPeriod=60
(五)log4j.propertity的配置:
log4j.rootLogger=warn, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n # Print only messages of level ERROR or above in the package noModule. log4j.logger.noModule=INFO # SHOWCASE log4j.logger.com.jgeppert.struts2.jquery.grid=DEBUG # Hibernate log4j.logger.org.hibernate=INFO log4j.logger.org.com.googlecode.s2hibernate=DEBUG # Struts2 log4j.logger.freemarker=INFO log4j.logger.com.opensymphony=INFO log4j.logger.com.opensymphony.xwork2.ognl=ERROR log4j.logger.org.apache.struts2=INFO log4j.logger.org.apache.struts2.components=INFO log4j.logger.org.apache.struts2.dispatcher=INFO log4j.logger.org.apache.struts2.convention=INFO