have been groping recently how to use a FASTDFS client connection with a connection pool, a client was found on the Mvnrepository Web site with the following MAVEN coordinates:
<Dependency> <groupId>Com.github.tobato</groupId> <Artifactid>Fastdfs-client</Artifactid> <version>1.25.4-release</version></Dependency>
The official documentation is integrated using Spring-boot.
It took some time. Finally, through the traditional XML form, gets the connection client object to the client.
The configuration content is as follows:
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd " > <!--Configuring the Scan package - <Context:component-scanBase-package= "Com.github.tobato.fastdfs.service,com.github.tobato.fastdfs.domain"/> <!--Configure Connection Manager - <BeanID= "Trackerconnectionmanager"class= "Com.github.tobato.fastdfs.conn.TrackerConnectionManager"> <Constructor-argname= "Pool"ref= "Fdfsconnectionpool"> </Constructor-arg> <!--Configure Fastdfs Tracker Server Ip:port address - < Propertyname= "Trackerlist"> <List> <value>192.168.24.39:22122</value> </List> </ Property> </Bean> <!--Configure connection Pooling - <BeanID= "Fdfsconnectionpool"class= "Com.github.tobato.fastdfs.conn.FdfsConnectionPool"> <!--inject Connection pool configuration - <Constructor-argname= "config" > <Beanclass= "Com.github.tobato.fastdfs.conn.ConnectionPoolConfig"/> </Constructor-arg> <!--Injection Connection Pool factory - <Constructor-argname= "Factory" > <Beanclass= "Com.github.tobato.fastdfs.conn.PooledConnectionFactory"/> </Constructor-arg> </Bean></Beans>
Specific instructions for use:
1. The client class that needs to be used is under the Com.github.tobato.fastdfs.service package, and the service package relies on classes under some com.github.tobato.fastdfs.domain packages.
such as Fastfilestorageclient, Appendfilestorageclient, generatestorageclient, etc.
2. Using Code instances
ImportCom.github.tobato.fastdfs.domain.StorePath;Importcom.github.tobato.fastdfs.service.FastFileStorageClient;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.test.context.ContextConfiguration;Importorg.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;ImportJava.io.File;ImportJava.io.FileInputStream; @ContextConfiguration (Locations= {"Classpath:applicationContext.xml"}) @RunWith (Springjunit4classrunner.class) Public classFastdfsdemoextendsabstractjunit4springcontexttests {@Test Public voidUploadFile ()throwsexception{File File=NewFile ("/home/duhui/code/fastdfsdemo/src/test/resources/images/54af9bcdn78b67b5a.jpg"); Storepath Storepath= Fastfilestorageclient.uploadfile (NULL,NewFileInputStream (file), File.length (), "JPG"); } @Autowired fastfilestorageclient fastfilestorageclient;
Spring integration: How to use fastdfsclient in a traditional way