备案网站建设,网站建设收费,网站设计与制作报价,上海网站建设 zl1.主要是配置文件#xff1a;如下#xff1a;(这里说明一下主要是看红色部分的配置#xff0c;其他的可以根据自己的实际情况修改#xff0c;这里只是个思路。) ?xml version1.0?
beans xmlnshttp://www.springframework.org/schema/beans…1.主要是配置文件如下(这里说明一下主要是看红色部分的配置其他的可以根据自己的实际情况修改这里只是个思路。) ?xml version1.0?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/tx xmlns:contexthttp://www.springframework.org/schema/contextxmlns:securityhttp://www.springframework.org/schema/securityxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd!-- 分散配置 --context:property-placeholder locationclasspath:jdbc.properties/!-- 组件扫描,此处的实现原理是递归扫描所有包效率较差。开发模式写法如下。后期调优可以将具体包名全部列到下面以逗号隔开 --context:component-scan base-packagecn.gov.csrc.*/!-- 配置c3p0数据源 --bean iddataSource classcom.mchange.v2.c3p0.ComboPooledDataSourceproperty namedriverClass value${jdbc.driverclass} /property namejdbcUrl value${jdbc.url} /property nameuser value${jdbc.username} /property namepassword value${jdbc.password} /property namemaxPoolSize value${c3p0.pool.size.max} /property nameminPoolSize value${c3p0.pool.size.min} /property nameinitialPoolSize value${c3p0.pool.size.ini} /property nameacquireIncrement value${c3p0.pool.size.increment} /property namemaxIdleTime value${cpool.maxIdleTime} //bean!-- 本地回话工厂bean,spring整合hibernate的核心入口 --bean idsessionFactory classorg.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean!-- 数据源 --property namedataSource refdataSource /!-- hibernate自身属性 --property namehibernatePropertiespropsprop keyhibernate.dialect${hibernate.dialect}/prop!-- 根据Bean自动生成数据库表,MySql5.5以后要使用org.hibernate.dialect.MySQL5InnoDBDialect才能创建成功 --prop keyhibernate.hbm2ddl.auto${hibernate.hbm2ddl.auto}/propprop keyhibernate.show_sql${hibernate.show_sql}/propprop keyhibernate.format_sqlfalse/propprop keyhibernate.temp.use_jdbc_metadata_defaultsfalse/prop!-- 开启二级缓存,其实hibernate默认就是开启的,这里显示的指定一下 --prop keyhibernate.cache.use_second_level_cachetrue/prop prop keyhibernate.autoReconnecttrue/prop!-- 指定二级缓存产品的提供商 -- !-- prop keyhibernate.cache.provider_classorg.hibernate.cache.EhCacheProvider/propprop keyhibernate.cache.use_query_cachetrue/prop --/props/propertyproperty namepackagesToScanlistvaluecn.gov.csrc.base.systemmanager.model/valuevaluecn.gov.csrc.report.model/valuevaluecn.gov.csrc.noreal.report.model/value/list/property/bean!-- hibernate事务管理器,在service层上实现事务管理,达到平台无关性 --bean idtxManager classorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory /property nameglobalRollbackOnParticipationFailure valuefalse //bean!-- 事务通知 --tx:advice idtxAdvice transaction-managertxManagertx:attributestx:method namesave* propagationREQUIRED isolationDEFAULT/tx:method nameupdate* propagationREQUIRED isolationDEFAULT/tx:method namedelete* propagationREQUIRED isolationDEFAULT/tx:method namebatch* propagationREQUIRED isolationDEFAULT/tx:method nameload* propagationREQUIRED isolationDEFAULT read-onlytrue/tx:method nameget* propagationREQUIRED isolationDEFAULT read-onlytrue/tx:method namefind* propagationREQUIRED isolationDEFAULT read-onlytrue/tx:method name* propagationREQUIRED isolationDEFAULT//tx:attributes/tx:advicebean idgenericLogger classcn.gov.csrc.base.log.GenericLogger/!-- aop配置 --aop:config!-- 切入点通知 --aop:advisor advice-reftxAdvice pointcutexecution(* cn.gov.csrc.base.security..*.*(..))/aop:advisor advice-reftxAdvice pointcutexecution(* *..*Service.*(..))//aop:configaop:config aop:pointcut idlogger expressionexecution(* *..*Dao.save*(..))or execution(* *..*Dao.update*(..))or execution(* *..*Dao.delete*(..))or execution(* *..*Dao.batch*(..)) / aop:aspect idloggerAspect refgenericLogger aop:around pointcut-reflogger methodinvoke / /aop:aspect /aop:config !-- 任务计划 --!-- 要调用的工作 --bean idtimerAction classcn.gov.csrc.report.action.TimerAction/beanbean idpraseXmlAction classcn.gov.csrc.report.action.PraseXmlAction/bean!-- 定义调用对象和调用对象的方法 --bean idjobtask classorg.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean!-- 调用的类 --property nametargetObjectref beantimerAction//property!-- 调用类中的方法 --property nametargetMethodvaluestart/value/property!-- 作业不并发调度 --property nameconcurrent valuefalse//bean!-- 定义调用对象和调用对象的方法 --bean idjobTask classorg.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean!-- 调用的类 --property nametargetObjectref beanpraseXmlAction//property!-- 调用类中的方法 --property nametargetMethodvalueparseXml/value/property!-- 作业不并发调度 --property nameconcurrent valuefalse//bean!-- 定义导出数据到xml的触发时间 --bean iddoTime classorg.springframework.scheduling.quartz.CronTriggerBeanproperty namejobDetailref beanjobtask//property!-- cron表达式 --property namecronExpression!-- 每天晚上11点59分钟59秒执行一次 --!-- value0 59 23 * * ?/value --value0 23 14 * * ?/value/property/bean!-- 定义解析xml的触发时间 --bean iddoPraseXml classorg.springframework.scheduling.quartz.CronTriggerBeanproperty namejobDetailref beanjobTask//property!-- cron表达式 --property namecronExpressionvalue0 24 14 * * ?/value/property/bean!-- 总管理类,如果将lazy-initfalse那么容器启动就会执行调度程序 --bean idstartQuertz lazy-initfalse autowireno classorg.springframework.scheduling.quartz.SchedulerFactoryBeanproperty nametriggerslistref beandoTime/ref beandoPraseXml//list/property/bean/beans 2.TimerAction.java: package cn.gov.csrc.report.action;import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;import javax.annotation.Resource;import org.apache.struts2.convention.annotation.Action;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Controller;import cn.gov.csrc.base.systemmanager.model.User;
import cn.gov.csrc.report.model.Accessory;
import cn.gov.csrc.report.model.Case;
import cn.gov.csrc.report.model.ReportedPerson;
import cn.gov.csrc.report.service.CaseService;Controller()
Scope(prototype)
Action(TimerAction)
public class TimerAction extends QuartzJobBean {private int timeout;public TimerAction() {}/** 调度工厂实例化后经过timeout时间开始执行调度 */public void setTimeout(int timeout) {this.timeout timeout;}Overrideprotected void executeInternal(JobExecutionContext context)throws JobExecutionException {System.out.println(定时任务执行中......);}/*** 定时导出外网数据到指定目录* throws Exception*/public void start() throws Exception { System.out.println(定时任务执行成功......);}}3.要解析的xml模板文件如下
(这里我的xml文件放到了D:\admin\2014-03-18目录下) ?xml version1.0 encodingGBK?
crsc data举报信息反馈R index1举报编号1/举报编号状态1/状态答复意见填写答复意见/答复意见/RR index2举报编号2/举报编号状态2/状态答复意见填写答复意见/答复意见/RR index3举报编号3/举报编号状态3/状态答复意见填写答复意见/答复意见/RR index4举报编号4/举报编号状态1/状态答复意见填写答复意见/答复意见/R/举报信息反馈/data
/crsc 4.PraseXmlAction.java: package cn.gov.csrc.report.action;import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;import org.apache.struts2.convention.annotation.Action;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Controller;Controller()
Scope(prototype)
Action(PraseXmlAction)
public class PraseXmlAction extends QuartzJobBean {private static final String xmlPath D:\\admin\\ getFileName() \\case.xml;public PraseXmlAction() {}Overrideprotected void executeInternal(JobExecutionContext arg0)throws JobExecutionException {// TODO Auto-generated method stubSystem.out.println(定时任务执行中......);}/*** 获取当前时间为文件夹名称* * return*/protected static String getFileName() {String fileNames null;Date date new Date();SimpleDateFormat formatDateFormat new SimpleDateFormat(yyyy-MM-dd);fileNames formatDateFormat.format(date);return fileNames;}/*** JDom解析xml文件*/public void parseXml() {try {ListElement elementList getElementList();for (Element element : elementList) {Element nameElement element.getChild(举报信息反馈);ListElement children nameElement.getChildren();for (Element element2 : children) {Element nameElement2 element2.getChild(举报编号);if (nameElement2 ! null) {System.out.println( nameElement2.getName() nameElement2.getTextTrim());}Element valueElement element2.getChild(状态);if (valueElement ! null) {System.out.println( valueElement.getName() valueElement.getTextTrim());}Element descriptElement element2.getChild(答复意见);if (descriptElement ! null) {System.out.println( descriptElement.getName() descriptElement.getTextTrim());}System.out.println(--------------------);}}} catch (Exception e) {System.out.println(e.getMessage());}}public static ListElement getElementList() throws FileNotFoundException,JDOMException, IOException {// 创建SAX建造者对象该类构造方法的重载boolean类型的方法中validate表示是否验证xml文档SAXBuilder saxBuilder new SAXBuilder(false);InputStream inputStream new FileInputStream(new File(xmlPath));// 解析xml文档返回document文档对象Document document saxBuilder.build(inputStream);// 获取根节点Element rootElement document.getRootElement();// 获取根节点下的第一个子节点ListElement elementList rootElement.getChildren();return elementList;}}