Junior — Middle
Milline Springi funktsioon või meetod kutsutakse pärast Bean initsialiseerimist selle loomise protsessis?
sobes.tech AI
Vastus AI-lt
In Spring, after the initialization of a Bean, the method annotated with @PostConstruct, if it exists, is called. Additionally, if the Bean implements the InitializingBean interface, the afterPropertiesSet() method is called.
You can also specify an initialization method via the init-method attribute in XML configuration or through the initMethod parameter in the @Bean annotation.
Example with @PostConstruct:
@Component
public class MyBean {
@PostConstruct
public void init() {
// initialization code
}
}
This ensures that Spring calls the specified method immediately after creating and configuring the Bean, but before its use.