Lazy load off,@Lazy (False), default to True
1 Importorg.springframework.beans.BeansException;2 ImportOrg.springframework.context.ApplicationContext;3 ImportOrg.springframework.context.ApplicationContextAware;4 ImportOrg.springframework.context.annotation.Lazy;5 ImportOrg.springframework.stereotype.Service;6 7 @Service8@Lazy (false)9 Public classSpringcontextutilImplementsApplicationcontextaware {Ten One Private StaticApplicationContext ApplicationContext =NULL;//Spring Application Context Environment A - /* - * the * Implementation of the Applicationcontextaware interface, the method must be implemented; - * - * Initialize member variables by passing the ApplicationContext parameter ApplicationContext - */ + - Public voidSetapplicationcontext (ApplicationContext ApplicationContext)throwsbeansexception { +Springcontextutil.applicationcontext =ApplicationContext; A } at - Public StaticApplicationContext Getapplicationcontext () { - returnApplicationContext; - } - -@SuppressWarnings ("Unchecked") in Public Static<T> T Getbean (String name)throwsbeansexception { - return(T) Applicationcontext.getbean (name); to } + -}
Get ApplicationContext NULL when implementing the Applicationcontextaware interface