Class SpringContext

  • All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

    @Component
    public class SpringContext
    extends Object
    implements org.springframework.context.ApplicationContextAware
    Helper class to provide access to Spring beans in classes not managed by Spring.
    • Constructor Detail

      • SpringContext

        public SpringContext()
    • Method Detail

      • getBean

        public static <T> T getBean​(Class<T> clazz)
        Returns the Spring managed bean instance of the given class type if it exists. Returns null otherwise.
        Type Parameters:
        T - type of the requested bean
        Parameters:
        clazz - the Class of the requested bean
        Returns:
        matching bean from the Spring context
      • setApplicationContext

        public void setApplicationContext​(org.springframework.context.ApplicationContext context)
                                   throws org.springframework.beans.BeansException
        Specified by:
        setApplicationContext in interface org.springframework.context.ApplicationContextAware
        Throws:
        org.springframework.beans.BeansException