简体   繁体   English

@PostConstrution被多次调用

[英]@PostConstrution called multiple times

I have created a class which implements two interfaces. 我创建了一个实现两个接口的类。

I have used a init method with @postconstruction annotation 我已经使用带有@postconstruction注解的init方法

I am observing that though bean is initialised only during start up, init method is called multiple times. 我观察到,虽然bean仅在启动时才初始化,但多次调用了init方法。

The @PostConstruct method will be called every time the bean is instantiated. 每次实例化bean时都会调用@PostConstruct方法。 This means either every time you do a "new", or, if you've registered your class with a @Service, @Repository, or any other anotation of sorts that registers the class as a spring bean, the first time you @Autowired it. 这意味着每次您执行“新”操作时,或者如果您已经向@ Service,@ Repository注册了类,或者将类注册为spring bean的任何其他类型的注释,则是第一次@Autowired它。

Watch out for instantations of the class aside from those if you are using another framework annotations like @ManagedBean in JSF, which could be instantiating your class without you realising it. 除了使用JSF中的@ManagedBean之类的其他框架注释外,还请注意类的实例化,这可能会在没有意识到的情况下实例化您的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM