我们在项目中可能会出现这样的需求,使用ftp上传很大的文件后对需要对文件进行相应的逻辑处理,这时我们可以使用apache ftpServer来处理这段逻辑,只要我们做相应的部署和编写我们的逻辑代码,这样通过ftp上传的文件会自动经过ftpServer来执行我们的逻辑判断,实现我们相应的功能!ftpServer是apache提供的纯java编写的Ftp服务器,能够方便的集成到J2EE项目中。采用这种集成方式无需在服务器端配置专门的FTP服务器。至于为什么要采用FTP服务器,是应一些大数据的上传所需。下面带领大家进入FtpServer的学习之旅

1、下载相应的jar包,任选一种方式

apache官网版本包下载:http://mina.apache.org/ftpserver-project/downloads.html

本人博客jar包整理版下载:http://download.csdn.net/detail/harderxin/6319669

2、将相应的jar包部署到我们的web projects中

3、将log4j.properties和users.properties放到我们项目的src目录下

上面只是ftp自带的一些配置

4、配置spring以及数据库连接池

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 读取配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
<!-- 数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass">
<value>${jdbc_driver}</value>
</property>
<property name="jdbcUrl">
<value>${jdbc_url}</value>
</property>
<property name="user">
<value>${jdbc_user}</value>
</property>
<property name="password">
<value>${jdbc_password}</value>
</property>
<property name="minPoolSize">
<value>2</value>
</property>
<property name="maxStatements" value="1000"></property>
<property name="maxPoolSize" value="5"></property>
<property name="idleConnectionTestPeriod" value="120"></property>
<property name="maxIdleTime" value="300"></property>
</bean> <!-- JdbcTemplate -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean> <bean id="ftpDao" class="com.ftp.service.FtpDaoImpl">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>

5、在application.xml(spring配置文件)添加Apache Ftpserver属性

<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="http://mina.apache.org/ftpserver/spring/v1"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd
"
id="myServer">
<listeners>
<nio-listener name="default" port="21">
<ssl>
<keystore file="ftpserver.jks" password="password" />
</ssl>
</nio-listener>
</listeners> <ftplets>
<ftplet name="ftpService">
<beans:bean class="com.ftp.service.FtpService">
<beans:property name="ftpDao" ref="ftpDao"></beans:property>
</beans:bean>
</ftplet>
</ftplets> <file-user-manager file="users.properties" encrypt-passwords="clear"/>
</server>

6、编写我们的监听器,目的是操作FtpServer

package com.ftp.util;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import org.apache.ftpserver.impl.DefaultFtpServer;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils; public class FtpServerListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent contextEvent) {
System.out.println("Stopping FtpServer");
DefaultFtpServer server = (DefaultFtpServer) contextEvent.getServletContext()
.getAttribute("FTPSERVER_CONTEXT_NAME");
if (server != null) {
server.stop();
contextEvent.getServletContext().removeAttribute("FTPSERVER_CONTEXT_NAME");
System.out.println("FtpServer stopped");
} else {
System.out.println("No running FtpServer found");
}
} public void contextInitialized(ServletContextEvent contextEvent) {
System.out.println("Starting FtpServer");
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(contextEvent.getServletContext());
DefaultFtpServer server = (DefaultFtpServer) ctx.getBean("myServer");
contextEvent.getServletContext().setAttribute("FTPSERVER_CONTEXT_NAME", server);
try {
server.start();
System.out.println("FtpServer started");
} catch (Exception e) {
throw new RuntimeException("Failed to start FtpServer", e);
}
}
}

7、在web.xml中配置Spring和我们编写的监听器

<?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"> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <listener>
<listener-class>com.ftp.util.FtpServerListener</listener-class>
</listener> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

这样我们的初步部署工作就完成了,如果启动不报错,说明我们配置成功!!接下来我们就要进行相应的逻辑监听处理了,见下篇文章--apache FtpServer 整合spring逻辑处理!!

apache FtpServer 整合spring部署的更多相关文章

  1. apache FtpServer整合spring逻辑处理

    上面我们的部署工作完成了,那么文件上传下载后,ftpserver会自动相应我们的上传下载操作,也就是说ftpServer服务器会得到触发,那么我们如果要得到文件的一些信息,比如说文件的路径.大小.类型 ...

  2. apache shiro整合spring(一)

    apache shiro整合spring 将shiro配置文件整合到spring体系中 方式一:直接在spring的配置文件中import shiro的配置文件 方式二:直接在web.xml中配置sh ...

  3. springboot整合apache ftpserver详细教程(看这一篇就够了)

    原创不易,如需转载,请注明出处https://www.cnblogs.com/baixianlong/p/12192425.html,否则将追究法律责任!!! 一.Apache ftpserver相关 ...

  4. android学习:Android上面部署Apache FTPServer

    经过了几天的研究,终于Apache FTPServer在Android的配置和使用上有了一些心得,现在分享出来,提供给大家参考,说到这儿又不得不吐槽一下这要命的转载了,找Apache FTPServe ...

  5. Maven 整合 spring profile实现多环境自动切换

    Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...

  6. webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成

    首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...

  7. eclipse环境下基于已构建struts2项目整合spring+hibernate

    本文是基于已构建的struts2项目基础上整合 spring+hibernate,若读者还不熟悉struts2项目,请先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 ...

  8. 整合Spring框架和Hibernate框架

    -------------------siwuxie095                                 整合 Spring 框架和 Hibernate 框架         1.导 ...

  9. 【WebService】——CXF整合Spring

    相关博客: [WebService]--入门实例 [WebService]--SOAP.WSDL和UDDI 前言: 之前的几篇博客基本上都是使用jdk来实现WebService的调用,没有使用任何框架 ...

随机推荐

  1. Java迭代器深入理解及使用

    Iterator(迭代器) 作为一种设计模式,迭代器可以用于遍历一个对象,对于这个对象的底层结构开发人员不必去了解. java中的Iterator一般称为“轻量级”对象,创建它的代价是比较小的.这里笔 ...

  2. UVA 10285 Longest Run on a Snowboard(记忆化搜索)

    Problem C Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 sec ...

  3. 浅析libev的ev_signal过程

    ev_signal是libev提供的对信号处理的一个模块,基本上是对sigaction函数的一个封装,并将本身是异步的信号转化为同步.ev_signal的使用十分简单: #include <ev ...

  4. mysql 基础技术

    一.树状结构 参考http://www.cnblogs.com/kingteach/archive/2011/07/05/2098046.html )) begin declare lev int; ...

  5. ios block使用

    BlockTest.h #import <Foundation/Foundation.h> typedef void (^didFinishBlock)(NSString *str); t ...

  6. Javascript 解构的用处

    对象的解构赋值,可以很方便地将现有对象的方法,赋值到某个变量. let { log, sin, cos } = Math; 上面代码将Math对象的对数.正弦.余弦三个方法,赋值到对应的变量上,使用起 ...

  7. J2EE之普通类载入web资源文件的方法

    在WEB中普通类并不能像Servlet那样通过this.getServletContext().getResourceAsStream()获取web资源,须要通过类载入器载入,这里有两种方式,这两种方 ...

  8. 基于RSA的加密/解密示例C#代码

    using System;using System.Security.Cryptography;using System.Text; class RSACSPSample{ static void M ...

  9. 在Ubuntu上为Android系统编写Linux内核驱动程序

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6568411 在智能手机时代,每个品牌的手机都有 ...

  10. Android窗口管理服务WindowManagerService计算窗口Z轴位置的过程分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8570428 通过前面几篇文章的学习,我们知道了 ...