基于netty封装。
下面步骤展示如何在Spring应用中接入fastdfs。
注:FastDFS JAR 包仅支持Java 8 或以上版本。
<dependency>
<groupId>com.github</groupId>
<artifactId>fastdfs-spring</artifactId>
<version>x.y.z</version>
</dependency>
<bean id="trackerNode" class="com.github.fastdfs.connection.TrackerNode">
<constructor-arg name="host" value="192.168.188.219"/>
<constructor-arg name="port" value="22122"/>
</bean>
<bean id="poolConfig" class="com.github.fastdfs.core.connection.FastDFSPoolConfig"></bean>
<bean id="fastDFSExecutor" class="com.github.fastdfs.core.FastDFSExecutor">
<property name="poolConfig" ref="poolConfig"/>
</bean>
<bean id="fastDFSConnectionFactory" class="com.github.fastdfs.connection.FastDFSConnectionFactory">
<property name="tracker" ref="trackerNode"/>
<property name="executor" ref="fastDFSExecutor"/>
</bean>
<bean id="fastDFSTemplate" class="com.github.fastdfs.core.FastDFSTemplate">
<property name="connectionFactory" ref="fastDFSConnectionFactory"/>
<property name="executor" ref="fastDFSExecutor"/>
</bean>
@Autowired
private FastDFSTemplate template;
@Test
public void testUpload() {
File file = new File("F:" + File.separator + "timg.jpg");
print(template.upload(file));
}
下面步骤展示如何在Spring Boot应用中接入fastdfs。
<dependency>
<groupId>com.github</groupId>
<artifactId>fastdfs-spring-boot-starter</artifactId>
<version>x.y.z</version>
</dependency>
fastdfs.host=localhost
fastdfs.port=22122
fastdfs.pool.connectTime=1000
...
@Autowired
private FastDFSTemplate template;
@Test
public void testUpload() {
File file = new File("F:" + File.separator + "timg.jpg");
print(template.upload(file));
}