1. @Scope 对应XML的bean scope 默认singleton
@Scope("prototype") @Component("movieFinderImpl ") public class MovieFinderImpl implements MovieFinder { // ... }
2. @PostConstruct = init-method; @PreDestroy = destroy-method;
PostConstruct 在构造之后执行方法
public class CachingMovieLister { @PostConstruct public void populateMovieCache() { // populates the movie cache upon initialization... } @PreDestroy public void clearMovieCache() { // clears the movie cache upon destruction... } }