如何为空arg构造函数提供init方法?(How to provide an init method for empty arg constructor?)
我有一些应该是
Serializable
类,因此需要一个空参数构造函数。 此外,我想为所有类实现提供一些自定义的init()
例程。到目前为止,我在无参数构造函数中使用了
init()
。 但是,由于我现在需要一个空的无参数构造函数来进行序列化,我如何确保所有实现的自动执行的init()
方法?例:
abstract class Foo implements Serializable { int id; Foo() { id = UUID.randomUUID(); } } class Bar extends Foo { Bar() {} Bar(String param) { //... } }
这就是我曾经拥有的。 始终为隐式的任何实现调用
Foo()
构造函数。 实现不必考虑任何UUID
生成。当我必须使
Foo()
成为Serialization
的空构造函数时,我怎样才能实现相同的目标?I have some classes that should be
Serializable
, thus require an empty argument constructor. Further I'd like to have some custominit()
routine for all class implementation.So far I had the
init()
just inside the no argument constructor. But as I now need an empty no-arg constructor for serialization, how can I ensure an auto-executedinit()
method for all implementations?Example:
abstract class Foo implements Serializable { int id; Foo() { id = UUID.randomUUID(); } } class Bar extends Foo { Bar() {} Bar(String param) { //... } }
This is what I used to have. The
Foo()
constructor is always called for any implementations implicit. The implementation does not have to take anyUUID
generation into account.How can I achieve the same when I have to necessarily make the
Foo()
an empty constructor forSerialization
?
原文:https://stackoverflow.com/questions/15730148
最满意答案
根据亚马逊文档如果您的帐户支持EC2 Classic,您可以制作现有实例的AMI,并将该AMI启动到EC2 Classic中。
要了解您的帐户是否支持EC2 Classic,请在AWS管理控制台 - > EC2服务下查看支持的平台。
Per the Amazon Documentation If your account supports EC2 Classic you can make an AMI of the existing instance, and launch that AMI into EC2 Classic.
To find out whether your account supports EC2 Classic look under AWS Management Console -> EC2 Service, under Supported Platforms.
相关问答
更多-
不,您无法将正在运行的实例从一个帐户移动到另一个帐户。 但是,您可以创建该实例的AMI并与其他帐户共享AMI。 记下“与特定用户共享AMI”: http://aws.amazon.com/articles/530 No, you cannot move an running instance from one account to another. You can however create an AMI of that instance and share the AMI with the other ...
-
如何使用Cloudformation从其他VPC EC2实例访问RDS(How I can access RDS from other VPC EC2 instance using Cloudformation)[2022-03-26]
有几件事。 您可能已创建VPC对等,但您需要转到与RDS和EC2实例的子网关联的路由表,并确保它们可以通话。 即,如果您的EC2实例位于子网10.0.X.XX中,则需要在RDS子网的路由表中使用VPC对等路径(可能显示为pcx-xxxx,pc表示'对等连接'的路径为10.0.X.XX并且EC2实例将需要使用VPC对等EC2的类似规则。 然后,您的安全组将需要允许您提到的流量。 至于通过CloudFormation更新现有安全组,是的,这是可能的。 您将需要使用SecurityGroupIngress(入站) ... -
CloudFormation:EC2未找到VPC并且未启动(CloudFormation: EC2 is not finding VPC and is not launching)[2022-07-09]
错误的原因在于: InstanceTenancy: dedicated VPC已配置为仅允许使用专用租户启动的实例。 但是, t2.micro不适用于专用租户,因此配置失败。 这导致了错误: 目前不支持请求的配置。 请查看文档以获取支持的配置。 删除InstanceTenancy要求或选择专用租户支持的实例类型 。 The cause of the error is here: InstanceTenancy: dedicated The VPC has been configured ... -
根据亚马逊文档如果您的帐户支持EC2 Classic,您可以制作现有实例的AMI,并将该AMI启动到EC2 Classic中。 要了解您的帐户是否支持EC2 Classic,请在AWS管理控制台 - > EC2服务下查看支持的平台。 Per the Amazon Documentation If your account supports EC2 Classic you can make an AMI of the existing instance, and launch that AMI into EC ...
-
检查您是否在CLI和控制台上使用相同的区域,因为VPC是按区域划分的,这可能是CLI和Web控制台之间差异的原因。 Check that you are using the same region on the CLI and the console, as VPCs are per-region, that may be the cause of the difference between CLI and web console.
-
如果VPC中有很少的实例连接到Classic,那么很容易为VPC中的每个实例在SG of Classic中添加规则。 但是您希望VPC中的任何当前/未来实例都能访问Classic。 虽然我没试过,但有些建议: 使用NAT将流量从VPC路由到Internet,并在Classic SG中指定NAT。 但是您无法直接访问VPC实例。 它非常适合私有子网中的实例。 根据您的描述,VPC实例位于公有子网中,此解决方案将无法运行。 使用代理(如Squid代理)并通过代理将流量从VPC路由到Classic实例。 启动实例 ...
-
在AWS Console上,您可以看到它。 如下所示: On AWS Console you can see it. Just like below:
-
EC2 Classic到VPC(EC2 Classic to VPC)[2023-12-30]
你无法将任何“LIVE”从classic转移到VPC。 您需要拍摄快照,创建AMI等等,然后从VPC内部的头开始重新启动整个事物。 没有其他出路。 对于安全组(SG),VPC SG和EC2-classic SG不会混在一起。 您必须在VPC内创建单独的SG。 您需要弄清楚您想要在VPC的公共子网中托管的所有内容(或VPC的私有子网)。 只能在公共子网内部进行访问。 例如,您可以将您的Web服务器放在公共子网中,而您可以将后端应用程序服务器放在私有子网中。 这只是一个例子。 总而言之,您最终将在VPC中启动所 ... -
单个EC2实例上的多个网站(或VPC分步指南!)(Multiple websites on a single EC2 instance (or VPC step-by-step guide!))[2021-07-07]
这是一个很好的,我只是使用它,它运作良好。 https://github.com/niftylettuce/amazon-vpc-ec2-multiple-ip-addresses/blob/master/Readme.md This is a good one, I just used it and it worked well. https://github.com/niftylettuce/amazon-vpc-ec2-multiple-ip-addresses/blob/master/Readme. ... -
Ec2Instance:Properties不支持Ec2Instance:Properties 使用SubnetId 。 "Ec2Instance" : { "Type" : "AWS::EC2::Instance", "Properties" : { "SecurityGroupIds" : [ { "Ref" : "xxxxx" } ], "Tags" : [ { "Key" : "Name", "Value" : "xxx" } ], "ImageId" : { "Fn ...