我有一个类直接映射JSON实现Mappable
(ObjectMapper框架)协议,我试图继承NSManagedObject
.
class AbstractModel: NSManagedObject, Mappable {
@NSManaged var uuid: String?
@NSManaged var updatedAt: String?
@NSManaged var createdAt: String?
required init?(_ map: Map) {
mapping(map)
}
func mapping(map: Map) {
uuid <- map["uuid"]
updatedAt <- map["updatedAt"]
createdAt <- map["createdAt"]
}
}
Run Code Online (Sandbox Code Playgroud)
这个实现的问题是编译器抱怨mapping(map)
在超级初始化器之前使用self:
AbstractModel.swift:19:9: Use of 'self' in method call 'mapping' before super.init initializes self
不幸的是我以前不能调用super initializer(super.init(entity: NSEntityDescription, insertIntoManagedObjectContext: NSManagedObjectContext?)
)mapping(map)
因为我需要self
得到它NSManagedObjectContext
.
我该怎么解决这个问题?
我尝试在 Spring Boot 应用程序中使用 AmazonSNS,并且可以在本地使用它,但是当我将其部署到开发服务器上时,我收到此错误:
Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@46a123e4: The requested metadata is not found at http://169.254.169.254/latest/meta-data/iam/security-credentials/ , com.amazonaws.auth.profile.ProfileCredentialsProvider@44bc2449: profile file cannot be null]
Run Code Online (Sandbox Code Playgroud)
如果我没有弄错的话,我的服务器将无法获取任何 AWS 凭证。我不明白为什么,因为 AWS_ACCESS_KEY_ID 和 AWS_SECRET_ACCESS_KEY 设置为环境变量。我的代码看起来像这样:
private AmazonSNS amazonSNS;
@Autowired
public AmazonSNSPublisherService() {
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).withRegion("eu-west-1").build();
}
Run Code Online (Sandbox Code Playgroud)
我试过这个:
this.amazonSNS = AmazonSNSClientBuilder.standard().withRegion("eu-west-1").build();
Run Code Online (Sandbox Code Playgroud)
和这个:
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(new EnvironmentVariableCredentialsProvider()).withRegion("eu-west-1").build();
Run Code Online (Sandbox Code Playgroud)
但我总是遇到同样的错误。