#1 constructor Injection vs properties Inject
constructor:
pro:
accountRepository
promote immutation;
concise;
constructor-arg can be in any order
con:
optional;
describle;
inherited automatically;
cyclic references;
#2 How to implement factory bean:
factory-method;
implement FactoryBean interface and the getObject() method (Auto-Detected by Spring Framework)
#3 @PostConstruct and @PreDestory
@PostConstruct
can be used to add behavior at startup after spring finishing initiating the bean object
@PreDestory
before bean object being destored.
The alternative in the xml configuration are init-method and destory-method
Best practice:
#1 Separate 'application" beans from "infrastructure" beans as infrastructure of changes between environments.
constructor:
pro:
accountRepository
promote immutation;
concise;
constructor-arg can be in any order
con:
optional;
describle;
inherited automatically;
cyclic references;
#2 How to implement factory bean:
factory-method;
implement FactoryBean interface and the getObject() method (Auto-Detected by Spring Framework)
#3 @PostConstruct and @PreDestory
@PostConstruct
can be used to add behavior at startup after spring finishing initiating the bean object
@PreDestory
before bean object being destored.
The alternative in the xml configuration are init-method and destory-method
Best practice:
#1 Separate 'application" beans from "infrastructure" beans as infrastructure of changes between environments.
Comments
Post a Comment