依赖pom.xml
<dependency>
<groupId>net.oschina.zcx7878</groupId>
<artifactId>fastdfs-client-java</artifactId>
</dependency>
配置文件bootstrap.yml
pingruan.base.enable-fastdfs=true
pingruan.base.fastdfs-connect-timeout=5
pingruan.base.fastdfs-network-timeout=30
pingruan.base.fastdfs-charset=UTF-8
pingruan.base.fastdfs-tracker-urls=192.168.111.164:22122
配置源码
//@Autowired
//StorageClient1 storageClient1;
/**
* 文件服务器配置
*
* @author vander
*
*/
@Configuration
@ConditionalOnProperty(value = "pingruan.base.enable-fastdfs", havingValue = "true")
@Slf4j
public class FastDFSConfig {
@Autowired
private BProperties bProperties;
@Bean
public StorageClient1 storageClient1() {
Properties props = new Properties();
TrackerServer trackerServer = null;
StorageServer storageServer = null;
try {
props.put("fastdfs.connect_timeout_in_seconds", bProperties.getFastdfsConnectTimeout());
props.put("fastdfs.network_timeout_in_seconds", bProperties.getFastdfsNetworkTimeout());
props.put("fastdfs.charset", bProperties.getFastdfsCharset());
props.put("fastdfs.tracker_servers", bProperties.getFastdfsTrackerUrls());
ClientGlobal.initByProperties(props);
TrackerClient tracker = new TrackerClient();
trackerServer = tracker.getConnection();
storageServer = tracker.getStoreStorage(trackerServer);
} catch (Exception e) {
log.error("fastdfs start error ..."+e.getMessage());
}
StorageClient1 storageClient1 = new StorageClient1(trackerServer, storageServer);
log.info("fastdfs start over ...");
return storageClient1;
}
}