How spring-managed classes invoke classes that are not spring managed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.