我们在项目中可能会出现这样的需求,使用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. UVA 10285 Longest Run on a Snowboard(记忆化搜索)

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

  2. JavaScript面向对象之类的继承

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. SqlServer 查询表、表说明、关联表、字段说明,语句汇总

    ----查询所有的表 SELECT * FROM SYSOBJECTS WHERE TYPE='U' ----根据表名查询所有的字段名及其注释 SELECT A.NAME,B.VALUE FROM S ...

  4. Direct3D 光照和材质

      今天我们来学习下Direct3D里面的光源和材质. 四大光照类型: 环境光 Ambient Light 一个物体没有被光照直接照射,通过每一些物体反射的光线到达这个物体,它也有可能被看到.这种称为 ...

  5. pyqt动态创建一系列组件并绑定信号和槽(网友提供学习)

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #如上图要求:创建指定多个复选框,一种是通过QT设计器Designe ...

  6. POJ1742:Coins(多重背包)

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

  7. thinkphp框架的路径问题 - 总结

    thinkphp框架的路径问题 - 总结 (2011-06-21 11:01:28) 转载▼ 标签: thinkphp 框架 路径 杂谈 分类: Php TP中有不少路径的便捷使用方法,比如模板中使用 ...

  8. 为项目编写Readme.MD文件

    了解一个项目,恐怕首先都是通过其Readme文件了解信息.如果你以为Readme文件都是随便写写的那你就错了.github,oschina git gitcafe的代码托管平台上的项目的Readme. ...

  9. bad interpreter: No such file or directory

    经常会遇到这种情况,在windows下写的脚本,代码会在linux下无法执行,错误就是: bad interpreter: No such file or directory 1.原因 这通常都是由于 ...

  10. [Spring入门学习笔记][静态资源]

    遗留问题 在上一节课的作业中,我们一定遇到了一点问题——虽然将页面内容正确的返回给了浏览器,但是浏览器显示的样式却是不正确的,这是因为在HTML的\标签中我们这样引入了CSS资源: <link ...