I found this very simple description on Apache FtpServer's document:
Integration with Spring Framework
Apache FtpServer uses Spring Framework to implement the configuration. That also means that we get the added benefit of full integration with regular Spring XML configuration. For example, you can embed the "server" element where ever you like within you 开发者_如何学GoSpring configuration, and with FtpServer on the classpath, Spring will wire up the server for you.
Nothing else about:
- Where should I put this configure file?
- What should the file name be?
- How could the application find that file?
Do I have study Spring's Configure Framework to know all about it?
There is documentation about that, and it wasn't too hard to find. It's on this page:
http://mina.apache.org/ftpserver-project/running_ftpserver_standalone.html
Turns out that you specify the XML configuration file simply on the command line when starting the server:
bin/ftpd.sh res/conf/ftpd-typical.xml
For Windows:
bin/ftpd.bat res/conf/ftpd-typical.xml
I just tried this for myself: I downloaded the server, fired off the command, and... it started serving.
Can't tell if the original questioner wanted to configure FtpServer via XML, or whether he/she doesn't know if that is a requirement of embedding.
As clearly shown in the product documentation, and as pointed out by other answers here, it's straight forward to configure FtpServer entirely programmatically.
But I figure that if the original questioner did want to do it, surely lots of people will recognize the administrative benefits to configuring FtpServer declaratively with XML in an embedded application. Here's how to do it:
Yes, you do need to use Spring to use XML configs for FtpServer, but you don't need to learn anything about Spring.
Just code this single statement to instantiate your FTP server, configured with the specified XML file:
FtpServer server = new FileSystemXmlApplicationContext("config/ftpd.xml").getBean("fServer", FtpServer.class);
(And you will obviously need to .start() it afterwards... that's it).
There are other ways to load the bean from the bean file, but this is simple and serviceable and it's easy enough for you to change your element's ID to match the specified bean name ("fServer" in the line above). The XML file path is relative to where the JVM ("java") is invoked from, but you can use an absolute path instead. You could also load the XML file as a CLASSPATH resource instead of from the filesystem. That has advantages and disadvantages and I won't take time here to discuss them, nor how to do that.
The only other thing to know is, you will require a couple Spring jar files in your compilation CLASSPATH, and many Spring jar files in your runtime CLASSPATH. ALl of these jars are readily available in the Maven central repository, and all together they come in at under 3 MB. Here are the jar dependencies in Ivy format:
<dependency name="mina-core" org="org.apache.mina" rev="2.0.4" conf="runtime"/>
<dependency name="slf4j-api" org="org.slf4j" rev="1.6.3" conf="runtime"/>
<dependency name="jcl-over-slf4j" org="org.slf4j" rev="1.6.3" conf="runtime"/>
<dependency name="slf4j-jdk14" org="org.slf4j" rev="1.6.3" conf="runtime"/>
<dependency name="ftplet-api" org="org.apache.ftpserver" rev="1.0.6" conf="runtime"/>
<dependency name="ftpserver-core" org="org.apache.ftpserver" rev="1.0.6"/>
<dependency name="spring-context" org="org.springframework"
rev="3.0.6.RELEASE"/>
<dependency name="spring-core" org="org.springframework"
rev="3.0.6.RELEASE"/>
<dependency name="spring-beans" org="org.springframework"
rev="3.0.6.RELEASE"/>
<dependency name="spring-asm" org="org.springframework" conf="runtime"
rev="3.0.6.RELEASE"/>
<dependency name="spring-expression" org="org.springframework" conf="runtime"
rev="3.0.6.RELEASE"/>
You were asking about embedded FTP server in another question. There are instructions for embedded usage. When embedding, you do not need any configuration files, you can use API to give server all the required information.
You do not need to know Spring configuration (unless you use Spring framework elsewhere in your project). The ftp library should take care of configuration automatically.
Using Embedding FtpServer in 5 minutes as example you can wire spring beans like this:
<bean id="ftpServer" factory-bean="ftpServerFactory" factory-method="createServer" init-method="start" />
<bean id="ftpServerFactory" class="org.apache.ftpserver.FtpServerFactory">
<property name="userManager">
<bean id="ftpUsers" factory-bean="ftpUsersFactory" factory-method="createUserManager" />
</property>
</bean>
<bean id="ftpUsersFactory" class="org.apache.ftpserver.usermanager.PropertiesUserManagerFactory">
<property name="file" value="users.properties" />
</bean>
It will start a FTP server on port 21 using user configuration from the properties file (I used the one provided in the release)
Spring's config mechanism is surprisingly simple yet flexible - essentially just an XML file defining a bunch of objects and their relationships (by specifying constructor parameters, invoking setters and so on - just like you would do from code).
One key point is that it wires together objects that are otherwise perfectly normal (no "Spring magic"). So you can take Spring components and use them independently of the config mechanism - handy for testing and re-use in other frameworks, or take external components and use them in a Spring project with no changes.
精彩评论