<beans>
??? <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
??<property name="driverClassName">
???<value>${jdbc.driverClassName}</value>
??</property>
??<property name="url">
???<value>${jdbc.url}</value>
??</property>
??<property name="username">
???<value>${jdbc.username}</value>
??</property>
??<property name="password">
???<value>${jdbc.password}</value>
??</property>
?</bean>
??? <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
??<property name="locations">
???<list>
????<value>classpath:/config/jdbc.properties</value>
????<value>classpath:/config/customer.properties</value>
???</list>
??</property>
?</bean>
?
?<bean id="ftpHandle" class="com.stt.dosp.datacollect.remote.FtpHandle"
??abstract="false" singleton="true" lazy-init="default"
??autowire="default" dependency-check="default">
??<property name="server">
???<value type="java.lang.String">${ftp.ip}</value>
??</property>
??<property name="user">
???<value type="java.lang.String">${ftp.user}</value>
??</property>
??<property name="password">
???<value type="java.lang.String">${ftp.password}</value>
??</property>
??<property name="remotePath">
???<value type="java.lang.String">${ftp.remotePath}</value>
??</property>
??<property name="localPath">
???<value type="java.lang.String">${ftp.localPath}</value>
??</property>
??<property name="temp">
???<value type="java.lang.String">${ftp.temp}</value>
??</property>
?</bean>
?
?<bean id="fileHandle"
??class="com.stt.dosp.datacollect.local.FileHandle" abstract="false"
??singleton="true" lazy-init="default" autowire="default"
??dependency-check="default">
??<property name="ftpHandle">
???<ref bean="ftpHandle" />
??</property>
??<property name="batchSize">
???<value type="java.lang.Long">${local.batch}</value>
??</property>
??<property name="backupDir">
???<value type="java.lang.String">${local.backup}</value>
??</property>
??<property name="doubleNameFix">
???<value type="java.lang.String">
????${local.double.name.fix}
???</value>
??</property>
??<property name="insertSQL">
???<value type="java.lang.String">${db.insert}</value>
??</property>
?</bean>
?
?<bean id="connectFtpServerTask"
??class="com.stt.dosp.datacollect.schedule.ConnectFtpServerTask"
??abstract="false" singleton="true" lazy-init="default"
??autowire="default" dependency-check="default">
??<property name="ftpHandle">
???<ref bean="ftpHandle" />
??</property>
?</bean>
???
??? <bean id="collectLocalTask"
??class="com.stt.dosp.datacollect.schedule.CollectLocalTask"
??abstract="false" singleton="true" lazy-init="default"
??autowire="default" dependency-check="default">
??<property name="fileHandle">
???<ref bean="fileHandle" />
??</property>
?</bean>
?
?<bean id="ftpConnectCheck" class="org.springframework.scheduling.timer.ScheduledTimerTask">
??<property name="timerTask">
???<ref bean="connectFtpServerTask" />
??</property>
??<property name="period">
???<value>${ftp.task.period}</value>
??</property>
??<property name="delay">
???<value>${ftp.task.delay}</value>
??</property>
?</bean>
?
?<bean id="localFileCheck" class="org.springframework.scheduling.timer.ScheduledTimerTask">
??<property name="timerTask">
???<ref bean="collectLocalTask" />
??</property>
??<property name="period">
???<value>${local.task.period}</value>
??</property>
??<property name="delay">
???<value>${local.task.delay}</value>
??</property>
?</bean>
?
?<bean id="timerBean" class="org.springframework.scheduling.timer.TimerFactoryBean">
??<property name="scheduledTimerTasks">
???<list>????
????<ref bean="ftpConnectCheck" />
????<ref bean="localFileCheck" />
???</list>
??</property>
?</bean>
?
?</beans>
--------->啟動類參考:
/**
?* 啟動類
?* @author zhangjp
?* @version 1.0
?*/
public class StartMain {
?/**
? * @param args
? */
??public static void main(String[] args) {
?? /*
? 只需要初始化一個taskBean就可以加載ScheduledTimerTask任務(wù)隊列
?? "<list>????
????? ?<ref bean="ftpConnectCheck" />
??????? <ref bean="localFileCheck" />
??? ??</list>"
??? 里的所有任務(wù)
? */
???SpringBeanFactory.getBean("connectFtpServerTask");??
???do{
?????? ??try {
????????????? ??Thread.sleep(1000);?
? ?//因為main類是一個進程,所以要使main不退出,加一個阻塞
?? //(使用Thread.sleep(1000);?或者Timer timer = new?Timer();都可以)
???????????} catch (InterruptedException e) {
?????????????? ?// TODO Auto-generated catch block
?????????????????? e.printStackTrace();
????????? ?}
???}while(true);
?
?}
}
---------->運行啟動類(可以編寫各個平臺的shell腳本,如 ".bat" ".sh"文件)
.bat腳本參考(windows):----->
@Echo Off
title dosp_collect
If %1.==CPGEN. GoTo :CPGEN
Rem ============= CLASSPATH ===================
Echo Generating classpath ...
Set CLASSPATH=
For %%X in (dospcollect-lib/*.jar) Do Call %0 CPGEN dospcollect-lib\%%X
For %%X in (common-lib/*.jar) Do Call %0 CPGEN common-lib\%%X
Rem ============= START DOSP COLLECT SERVER ===================
Echo Starting Dosp Collect Server ...
java? -Xms128m -Xmx256m? -classpath %CLASSPATH% com.stt.dosp.datacollect.startup.StartMain
GoTo :END
Rem ============= CLASSPATH HELP ===================
Rem This target is used to concatenate the classpath parts
:CPGEN
Set CLASSPATH=%CLASSPATH%;%2
Rem ============= END ===================
Rem Target needed to jump to the end of the file
:END
.sh腳本參考(linux/unix)----->
#!/bin/bash
# don't run? DOSP COLLECT Server as root
if [ $UID -eq 0 ] ; then
?echo
?echo "For security reasons you should not run this script as root!"
?echo
?exit 1
fi?
# go to current directory
cd `dirname $0`/..
# defining some variables
COMMON_LIB="common-lib"
DOSP_LIB="dospcollect-lib"
# generating the proper classpath
echo "Generating classpath ..."
CLASSPATH=""
for N in $COMMON_LIB/*.jar; do CLASSPATH="$CLASSPATH$N:"; done?
for N in $DOSP_LIB/*.jar; do CLASSPATH="$CLASSPATH$N:"; done?
# startup? DOSP COLLECT Server
echo "Starting? Dosp-Collect Server ..."
java? -Xms128m -Xmx256m -classpath $CLASSPATH com.stt.dosp.datacollect.startup.StartMain