I want to use a bind object in my service class with guice in dropwizard.
Consider the object
public class MinioData {
private String endpoint;
public String getEndpoint() {
return endpoint;
}
}
And a service
@Path("/upload")
@Produces(MediaType.APPLICATION_JSON)
public class UploadResource {
private final MinioData minioData;
@Inject
public UploadResource(
@Named("miniodata") MinioData minioData) {
this.minioData = minioData;
}
How can I bind this object so that can be used in my service. For a String I could use
bindConstant()
.annotatedWith(Names.named("miniodata"))
.to(configuration.getMiniodata());
but since in this case it is a general object how would I bind it?
如果在DW应用程序中配置了现有的Guice模块,则只需将MinioData实例从配置对象绑定到关联的类:
binder.bind(MinioData.class).toInstance(configuration.getMiniodata());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.