@PostConstruct

The PostConstruct annotation is used on a method that needs to be executed
after dependency injection is done to perform any initialization. This
method MUST be invoked before the class is put into service. This
annotation MUST be supported on all classes that support dependency
injection. The method annotated with PostConstruct MUST be invoked even
if the class does not request any resources to be injected. Only one
method can be annotated with this annotation. The method on which the
PostConstruct annotation is applied MUST fulfill all of the following
criteria:

PostConstruct批注用于需要执行的方法
在完成依赖注入后,将执行任何初始化。 这个
方法必须在类投入使用之前被调用。 这个
所有支持依赖项的类都必须支持注释
注射。 带有PostConstruct注释的方法甚至必须被调用
如果该类不要求注入任何资源。 只有一个
可以使用此注释对方法进行注释。 的方法
应用PostConstruct注释必须满足以下所有条件
准则:

The method MUST NOT have any parameters except in the case of
interceptors in which case it takes an InvocationContext object as
defined by the Interceptors specification.

除以下情况外,该方法不得具有任何参数:
在这种情况下,拦截器将InvocationContext对象作为
由拦截器规范定义。

The method defined on an interceptor class MUST HAVE one of the
following signatures:
在拦截器类上定义的方法必须具有以下一种
以下签名:
void (InvocationContext)
Object (InvocationContext) throws Exception

Note: A PostConstruct interceptor method must not throw application
exceptions, but it may be declared to throw checked exceptions including
the java.lang.Exception if the same interceptor method interposes on
business or timeout methods in addition to lifecycle events. If a
PostConstruct interceptor method returns a value, it is ignored by
the container.

注意:PostConstruct拦截器方法不得引发应用程序
异常,但是可以声明抛出检查异常,包括
如果插入相同的拦截器方法,则返回java.lang.Exception
生命周期事件之外的业务或超时方法。 如果一个
PostConstruct拦截器方法返回一个值,该值将被忽略
容器。

The method defined on a non-interceptor class MUST HAVE the
following signature:
在非拦截器类上定义的方法必须
以下签名:

void ()

The method on which PostConstruct is applied MAY be public, protected,
package private or private.
The method MUST NOT be static except for the application client.
The method MAY be final.
If the method throws an unchecked exception the class MUST NOT be put into
service except in the case of EJBs where the EJB can handle exceptions and
even recover from them.

应用PostConstruct的方法可以是公开的,受保护的,
打包私有或私有。
除了应用程序客户端,该方法一定不能是静态的。
该方法可以是最终的。
如果该方法抛出未经检查的异常,则该类不得放入
服务,但EJB可以处理异常和
甚至从他们那里康复。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值