Announcement Announcement Module
No announcement yet.
List of pre-configured injectable objects in Spring? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • List of pre-configured injectable objects in Spring?

    I noticed that some Spring samples use
    private Environment environment;
    to inject a org.springframework.core.env.Environment. Or as the Javadoc says:
    Beans managed within an ApplicationContext may register to be EnvironmentAware or @Inject the Environment in order to query profile state or resolve properties directly.
    Is there an exhaustive list of objects (besides Environment) provided by Spring that a Spring user may be interested to inject in one's beans?

  • #2
    It's not an extensive list, but you may inject the following:

    - Bean's name in spring container. Implement BeanNameAware.
    - ApplicationContext in which the bean is created. Implement ApplicationContextAware, or inject the ApplicationContext with @Autowired.
    -Bean factory that created the bean. Implement BeanFactoryAware
    -ClassLoader used by the Bean factory. Implement BeanClassLoaderAware


    • #3
      I just came across another bean-out-of-the-box (at least when used in conjunction with Spring Security?):

      As the documentation points out:

      The first thing you need to do is add the following filter declaration to your web.xml file:

      <filter-class>org.springframework.web.filter.DelegatingFil terProxy</filter-class>


      This provides a hook into the Spring Security web infrastructure. DelegatingFilterProxy is a Spring Framework class which delegates to a filter implementation which is defined as a Spring bean in your application context. In this case, the bean is named “springSecurityFilterChain”, which is an internal infrastructure bean created by the namespace to handle web security. Note that you should not use this bean name yourself.
      Now I'm curious to know the place in Spring's/Spring Security's source code where this bean gets initially created.


      • #4
        I stumbled upon several bean name constants in the Spring Framework Javadoc's constant field values list. These constants can be identified by the "_BEAN_NAME" suffix, for instance ENVIRONMENT_BEAN_NAME = "environment".

        The "environment" bean is registered with a BeanFactory/BeanRegistry in class AbstractApplicationContext.

        So anybody who is interested to get to know a few default beans registered with any ApplicationContext (e.g. the "systemEnvironment") may look through the constant field value list searching for "_BEAN_NAME".