@Service注解作用
1、 其getBean的默認名稱是類名(頭字母小寫),可以@Service(“xxxx”)這樣來指定,
2、其定義的bean默認是單例的,可以使用@Service(“beanName”) @Scope(“prototype”)來改變。
3、可以通過@PostConstruct和@PreDestroy指定初始化方法和銷毀方法(方法名任意)
@Service("baseCacheService")
public class BaseCacheServiceImpl implements BaseCacheService{
}
@Service
public class ShortUrlServiceImpl implements ShortUrlService {
}
備注:
1、過濾器中可以通過如下方式獲取bean
BeanFactory factory = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
ShortUrlService shortUrlService = (ShortUrlService) factory.getBean("shortUrlServiceImpl");
BaseCacheService baseCacheService = (BaseCacheService) factory.getBean("baseCacheService");
