Skip to content

Private init/destroy method may be invoked twice #28083

@levitin

Description

@levitin

Imagine, you have a bean with an init method, annotated with @PostConstruct and a configuration class, referencing the same init method on its own.

public class MyBean {

    @PostConstruct
    public void init() {
        ...
    }

}
@Configuration
public class MyConfiguration {

    @Bean(initMethod = "init")
    public MyBean myBean() {
        return new MyBean();
    }
}

The init method will be invoked only once (what is pretty well).

This is true for all method modifiers except private.
As soon as you change the method modifier to private the init method is invoked twice.

public class MyBean {

    @PostConstruct
-    public void init() {
+    private void init() {
        ...
    }
}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions