1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.context;
  17. import org.springframework.beans.BeansException;
  18. /**
  19. * Interface to be implemented by any object that wishes to be notified
  20. * of the ApplicationContext that it runs in.
  21. *
  22. * <p>Implementing this interface makes sense for example when an object
  23. * requires access to a set of collaborating beans. Note that configuration
  24. * via bean references is preferable to implementing this interface just
  25. * for bean lookup purposes.
  26. *
  27. * <p>This interface can also be implemented if an object needs access to file
  28. * resources, i.e. wants to call getResource, or access to the MessageSource.
  29. * However, it is preferable to implement the more specific ResourceLoaderAware
  30. * interface respectively receive a reference to the MessageSource bean in that
  31. * scenario.
  32. *
  33. * <p>Note that Resource dependencies can also be exposed as bean properties
  34. * of type Resource, populated via Strings with automatic type conversion by
  35. * the bean factory. This removes the need for implementing any callback
  36. * interface just for the purpose of accessing a specific file resource.
  37. *
  38. * <p>ApplicationObjectSupport is a convenience base class for
  39. * application objects, implementing this interface.
  40. *
  41. * <p>For a list of all bean lifecycle methods, see the BeanFactory javadocs.
  42. *
  43. * @author Rod Johnson
  44. * @see ResourceLoaderAware
  45. * @see org.springframework.context.support.ApplicationObjectSupport
  46. * @see org.springframework.beans.factory.BeanFactoryAware
  47. * @see org.springframework.beans.factory.InitializingBean
  48. * @see org.springframework.beans.factory.BeanFactory
  49. */
  50. public interface ApplicationContextAware {
  51. /**
  52. * Set the ApplicationContext that this object runs in.
  53. * Normally this call will be used to initialize the object.
  54. * <p>Invoked after population of normal bean properties but before an init
  55. * callback like InitializingBean's afterPropertiesSet or a custom init-method.
  56. * Invoked after ResourceLoaderAware's setResourceLoader.
  57. * @param applicationContext ApplicationContext object to be used by this object
  58. * @throws ApplicationContextException in case of applicationContext initialization errors
  59. * @throws BeansException if thrown by application applicationContext methods
  60. * @see org.springframework.beans.factory.BeanInitializationException
  61. */
  62. void setApplicationContext(ApplicationContext applicationContext) throws BeansException;
  63. }