锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 涓撴敞浜庡垎浜獼ava鍚庣鐩稿叧鎶鏈佽佸徃鏈哄疄鎴樺共璐э紝涓嶉檺浜嶫VM銆佸茍鍙戙佽璁℃ā寮忋佹ц兘浼樺寲銆佸垎甯冨紡&寰湇鍔°佷簯鍘熺敓銆佸ぇ鏁版嵁鐩稿叧涓婚銆?/span>
Java鐖卞ソ鑰呯ぞ鍖?/strong>
鍏紬鍙峰唴瀹圭畝浠嬶細
甯屾湜鍏蟲敞鐨勪綘鍋滀笅鑴氭錛屽畾鏈夋墍鏀惰幏銆?/span>
浠ュ墠鐨勪釜浜哄崥瀹㈠唴瀹逛笉濂借縼縐伙紝鎵浠ユ垜鎵撶畻鏍規嵁鑷繁鐨勫騫寸粡楠岋紝涓嶆柇鏁寸悊杈撳嚭鏈変環鍊肩殑鍐呭銆?br />鐩墠鍏紬鍙峰唴瀹規湁鍏充簬SpringCloud錛堝井鏈嶅姟妗嗘灦錛夈丼kywalking錛圓PM鐩戞帶璋冪敤閾撅級銆丣VM錛圙C鍒嗘瀽銆佸唴瀛樻硠婕忓垎鏋愶級銆佸茍鍙戠紪紼?/span>鐩稿叧鍘熷垱瀹炴垬鏂囩珷宸插嚭鐐夈?br />
鏈榪戝垰寮濮嬪凡緇忔湁涓嶅皯灝忎紮浼村叧娉ㄤ簡錛屾湡寰呰兘鏈夊垢鎼滅儲鍒版湰鍗氬鐨勫悓瀛︼紝鍙互鎵爜鍏蟲敞涓涓嬶紝涓嶈儨鎰熸縺銆?br />澶у鏈変換浣曟妧鏈佽亴鍦恒侀潰璇曚笂鐨勯棶棰橀兘鍙互涓庢垜浜ゆ祦銆?br />
鏂瑰紡涓錛?/strong>鎵爜浠ヤ笅鍏紬鍙蜂簩緇寸爜錛?/strong>
鏂瑰紡浜岋細鍦ㄥ井淇′笂鐩存帴鎼滅儲錛?nbsp;javatech_cbo
鎰熻阿鍚勪綅灝忎紮浼寸殑鏀寔錛屽悗緇細鍦ㄨ鍏紬鍙蜂笂杈撳嚭澶ч噺鐨勬湁浠峰肩殑瀹炴垬騫茶揣 錛屾湡寰呬笌浣犱竴鍚岃繘姝ヤ笌鎴愰暱銆?br />
]]>
]]>
]]>
]]>
]]>
]]>
]]>
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id= "propertyConfigurer"
class = "com.ccms.base.util.DecryptPropertyPlaceholderConfigurer" >
<property name="locations" value= "classpath:sysConfig.properties" />
</bean>
<!--
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>${dataSource.jdbcUrl}&useUnicode=true&characterEncoding=UTF-8</value>
</property>
<property name="username">
<value>${dataSource.userName}</value>
</property>
<property name="password">
<value>${dataSource.password}</value>
</property>
<property name="maxActive">
<value>100</value>
</property>
<property name="initialSize">
<value>5</value>
</property>
<property name="maxIdle">
<value>10</value>
</property>
<property name="minIdle">
<value>0</value>
</property>
<property name="maxWait">
<value>-1</value>
</property>
<property name="defaultAutoCommit">
<value>false</value>
</property>
<property name="testOnBorrow">
<value>true</value>
</property>
<property name="testWhileIdle">
<value>true</value>
</property>
<property name="timeBetweenEvictionRunsMillis">
<value>600000</value>
</property>
<property name="numTestsPerEvictionRun">
<value>20</value>
</property>
<property name="minEvictableIdleTimeMillis">
<value>3600000</value>
</property>
</bean>
-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="${dataSource.jdbcUrl}&useUnicode=true&characterEncoding=UTF-8" />
<property name="user" value="${dataSource.userName}" />
<property name="password" value="${dataSource.password}" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="50" />
<property name="maxStatements" value="0" />
<property name="idleConnectionTestPeriod" value="60" />
<property name="acquireRetryAttempts" value="3" />
</bean>
<!-- Session Factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<!-- hbm閰嶇疆鏂囦歡鐨刢lassPath璺緞 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/ccms/base/mapping</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<!-- <prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop> -->
</props>
</property>
</bean>
<bean id="myTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="myTransactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor"
ref="transactionInterceptor" />
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Service</value>
<value>*Biz</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
</beans>
鍚姩tomcat鍚庢姤鍑哄涓嬮敊璇俊鎭細
------------------------------------------
璇︾粏瑙f瀽鍙互鍙傜収榪欑瘒鏂囩珷錛?a >http://netfork.iteye.com/blog/286215
]]>
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
/**
*
* 鐩殑:FTP鏂囦歡綾?br />
* <br/>
*
* FTP涓婁紶鏂囦歡銆佷笅杞芥枃浠?br />
*
* *
*/
public class FTPUtil {
private static final Log log = LogFactory.getLog(FTPUtil.class);
public static int download(String ip,int port,String userName,String password,FileFilter filter,String localFilePath) throws SocketException, IOException{
return download(ip, port, userName, password, null,filter, localFilePath);
}
public static int download(String ip,int port,String userName,String password,String ftpPath,FileFilter filter,String localFilePath) throws SocketException, IOException{
FTPClient ftp = new FTPClient();
int i=0;
try {
// 涓嶄負絀鴻繛鎺?閫氳繃IP 鍜岀鍙?br />
ftp.connect(ip, port);
// 鐧婚檰
if (ftp.login(userName, password)) {
ftp.enterLocalPassiveMode();
// 鑾峰彇FTP鐧婚檰鐩綍涓嬬殑鎵鏈夋枃浠?br />
if(ftpPath!=null){
if(!ftp.changeWorkingDirectory(ftpPath)){
throw new RuntimeException("鎵句笉鍒拌鐩綍:"+ftpPath);
}
}
FTPFile[] files = ftp.listFiles();
for (FTPFile file : files) {
String fileName = file.getName();
if (filter.accept(fileName)) {
BufferedOutputStream out = null;
try {
// IO嫻佷笅杞芥枃浠跺埌鏈湴
out = new BufferedOutputStream(
new FileOutputStream(new File(localFilePath
,fileName)));
// 寮濮嬩笅杞?br />
ftp.retrieveFile(file.getName(), out);
log.info("涓嬭澆鏂囦歡:" + file.getName() + "鍒版湰鍦拌礬寰?"
+ localFilePath);
i++;
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception e) {
log.error("", e);
}
}
}
}
} else {
i = -1;
}
} finally {
if(ftp != null&&ftp.isConnected()){
try {
log.info("鍏抽棴ftp榪炴帴");
ftp.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return i;
}
public static int download(String ip,int port,String userName,String password,String ftpPath,final String fileName,String localFilePath)throws SocketException, IOException{
return download(ip, port, userName, password,ftpPath,new FileFilter(){
public boolean accept(String fileName1) {
return fileName.equalsIgnoreCase(fileName1);
}
}, localFilePath);
}
public static int download(String ip,int port,String userName,String password,final String fileName,String localFilePath)throws SocketException, IOException{
return download(ip, port, userName, password,null,fileName, localFilePath);
}
/**
* ftp涓婁紶鏂囦歡鑷蟲湇鍔″櫒
* @throws SocketException
* @throws IOException
*/
public static void uploadFile(String ip, int port, String userName, String password, String localFile)
throws SocketException, IOException{
log.info("涓婁紶鏈湴鏂囦歡: " + localFile);
File file = new File(localFile);
InputStream in = null;
FTPClient ftpClient = null;
if(file != null){
try {
ftpClient = new FTPClient();
in = new FileInputStream(file);
ftpClient.connect(ip,port);
if(ftpClient.login(userName, password)){
ftpClient.enterLocalPassiveMode();
boolean flag= ftpClient.appendFile(file.getName(), in);
log.info("涓婁紶鏂囦歡鎴愬姛:" + flag);
}
}catch (SocketException e) {
log.error("ftp涓婁紶鏂囦歡澶辮觸:", e);
throw e;
}catch (IOException e) {
log.error("ftp涓婁紶鏂囦歡澶辮觸:", e);
throw e;
} finally{
if(in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(ftpClient != null){
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
public static void upload(String ip, int port, String userName, String password, String path,String remotePath)
throws SocketException, IOException{
upload(ip, port, userName, password, new File(path), remotePath);
}
/**
* ftp涓婁紶鏂囦歡鑷蟲湇鍔″櫒
* @throws SocketException
* @throws IOException
*/
public static void upload(String ip, int port, String userName, String password, File localFile,String remotePath)
throws SocketException, IOException{
log.info("涓婁紶鏈湴鏂囦歡: " + localFile.getName());
InputStream in = null;
FTPClient ftpClient = null;
if(localFile != null){
try {
ftpClient = new FTPClient();
in = new FileInputStream(localFile);
ftpClient.connect(ip,port);
if(ftpClient.login(userName, password)){
ftpClient.enterLocalPassiveMode();
if(remotePath!=null){
if(!ftpClient.changeWorkingDirectory(remotePath)){
ftpClient.makeDirectory(remotePath);
ftpClient.changeWorkingDirectory(remotePath);
}
}
boolean flag= ftpClient.storeFile(localFile.getName(), in);
log.info("涓婁紶鏂囦歡鎴愬姛:" + flag);
}
}catch (SocketException e) {
log.error("ftp涓婁紶鏂囦歡澶辮觸:", e);
throw e;
}catch (IOException e) {
log.error("ftp涓婁紶鏂囦歡澶辮觸:", e);
throw e;
} finally{
if(in != null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(ftpClient != null){
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
}