IOC Annotation_Pre_Post_Scope

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... } }

猜你喜欢

转载自leon-s-kennedy.iteye.com/blog/1536023
ioc