Spring Example¶
This is an example of how to use our library with Spring.
Please, get acquainted with the Basic Example first.
The possible configuration settings can be found here.
Required Dependencies¶
<dependency>
<groupId>org.carlspring.cloud.aws</groupId>
<artifactId>s3fs-nio</artifactId>
<version>1.0.6</version>
</dependency>
compile group: 'org.carlspring.cloud.aws', name: 's3fs-nio', version: '1.0.6'
libraryDependencies += "org.carlspring.cloud.aws" % "s3fs-nio" % "1.0.6"
Spring Code Example¶
import static org.carlspring.cloud.storage.s3fs.S3Factory.ACCESS_KEY;
import static org.carlspring.cloud.storage.s3fs.S3Factory.SECRET_KEY;
@Configuration
public class AwsConfig
{
@Value("${aws.accessKey}")
private String accessKey;
@Value("${aws.secretKey}")
private String secretKey;
@Bean
public FileSystem s3FileSystem()
throws IOException
{
Map<String, String> env = new HashMap<>();
env.put(ACCESS_KEY, accessKey);
env.put(SECRET_KEY, secretKey);
return FileSystems.newFileSystem(URI.create("s3:///"),
env,
Thread.currentThread().getContextClassLoader());
}
}
Now you can inject in any spring component:
@Inject
private FileSystem s3FileSystem;