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. import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
  19. import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
  20. /**
  21. * SPI interface to be implemented by most if not all application contexts.
  22. * Provides means to configure an application context in addition to the
  23. * application context client methods in the ApplicationContext interface.
  24. *
  25. * <p>Configuration and lifecycle methods are encapsulated here to avoid
  26. * making them obvious to ApplicationContext client code.
  27. *
  28. * @author Juergen Hoeller
  29. * @since 03.11.2003
  30. */
  31. public interface ConfigurableApplicationContext extends ApplicationContext {
  32. /**
  33. * Set the parent of this application context.
  34. * <p>Note that the parent shouldn't be changed: It should only be set outside
  35. * a constructor if it isn't available when an object of this class is created,
  36. * for example in case of WebApplicationContext setup.
  37. * @param parent the parent context
  38. * @see org.springframework.web.context.ConfigurableWebApplicationContext
  39. */
  40. void setParent(ApplicationContext parent);
  41. /**
  42. * Add a new BeanFactoryPostProcessor that will get applied to the internal
  43. * bean factory of this application context on refresh, before any of the
  44. * bean definitions get evaluated. To be invoked during context configuration.
  45. * @param beanFactoryPostProcessor the factory processor to register
  46. */
  47. void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor);
  48. /**
  49. * Load or refresh the persistent representation of the configuration,
  50. * which might an XML file, properties file, or relational database schema.
  51. * @throws org.springframework.context.ApplicationContextException if the config cannot be loaded
  52. * @throws org.springframework.beans.BeansException if the bean factory could not be initialized
  53. */
  54. void refresh() throws BeansException;
  55. /**
  56. * Return the internal bean factory of this application context.
  57. * Can be used to access specific functionality of the factory.
  58. * <p>Note that this is just guaranteed to return a non-null instance
  59. * <i>after</i> the context has been refreshed at least once.
  60. * <p>Note: Do not use this to post-process the bean factory; singletons
  61. * will already have been instantiated before. Use a BeanFactoryPostProcessor
  62. * to intercept the bean factory setup process before beans get touched.
  63. * @see #refresh
  64. * @see #addBeanFactoryPostProcessor
  65. */
  66. ConfigurableListableBeanFactory getBeanFactory();
  67. /**
  68. * Close this application context, releasing all resources and locks that the
  69. * implementation might hold. This includes disposing all cached singleton beans.
  70. * <p>Note: Does <i>not</i> invoke close on a parent context.
  71. * @throws org.springframework.context.ApplicationContextException if there were fatal errors
  72. */
  73. void close() throws ApplicationContextException;
  74. }