How spring-managed classes invoke classes that are not spring-managed.
is to use a spring-provided perceptual concept that injects the context when the container is Started.
The following is a tool class.
1 Importorg.springframework.beans.BeansException;2 Importorg.springframework.context.ApplicationContext;3 Importorg.springframework.context.ApplicationContextAware;4 Importorg.springframework.stereotype.Component;5 6 /**7 * holder of Spring context:8 * Applicationcontextaware can perceive applicationcontex,9 * As long as the class that implements the interface is given to spring management, spring can perceiveTen * The setapplicationcontext is injected into the context of the current container when it is Perceived. one * @authorLne a */ - @Component - public classSpringapplicationcontextholderImplementsApplicationcontextaware { the - //use a variable to accept ApplicationContext - Private StaticApplicationContext CTX =NULL; - + @Override - public voidSetapplicationcontext (applicationcontext Ctx)throwsbeansexception { + System.out.println (ctx); aSpringapplicationcontextholder.ctx =ctx; at } - - public StaticObject Getbean (String Name) { - - returnCtx.getbean (name); - } in - public StaticObject Getbean (Class clazz) { to + returnCtx.getbean (clazz); - } the}
How spring-managed classes invoke classes that are not spring managed