PostConstruct class

Marks a method the container calls once a bean is fully injected, before anyone uses it.

Use it for setup that needs the injected fields: warming a cache, checking settings, opening a connection. The constructor is too early for that when fields or setters are injected. The method takes no arguments. It may return a Future; then the context must be started with refreshAsync (or runAsync), which waits for it.

@Component()
class Cache {
  @PostConstruct()
  void warmUp() { /* load entries */ }
}

Spring (Java), the Jakarta annotation:

@Component
class Cache {
  @PostConstruct
  void warmUp() { ... }
}

Constructors

PostConstruct()
Marks the init method.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited