Skip to content

Make AbstractApplicationContext BeanNameAware [SPR-4384] #9063

Closed

Description

@spring-projects-issues

Kenny MacLeod opened SPR-4384 and commented

Would it be possible for AbstractApplicationContext to implement the BeanNameAware interface, and to then expose that bean name as a property?

My use case is when beanRefContext.xml contains multiple named contexts, and the beans within those contexts need to access the name of their context.

I can't think of any immediately obvious side-effects to this.


Affects: 2.5.1

Issue Links:

Activity

  1. spring-projects-issues commented on Feb 4, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've added a "getId()" method to the ApplicationContext interface, with a corresponding "setId" in AbstractApplicationContext class. The newly introduced AbstractRefreshableConfigApplicationContext base class (which ClassPathXmlApplicationContext and FileSystemXmlApplicationContext derive from) implements BeanNameAware and calls "setId" with the bean name if no id has been configured explicitly.

    Furthermore, ClassPathXmlApplicationContext and FileSystemXmlApplicationContext allow for bean-style configuration now, with default constructors, "configLocation" and "configLocations" properties and automatic refresh triggered by the afterPropertiesSet callback. This is what I would consider the preferred way of setting up a context in a beanRefContext file, with full configurability and proper bean-style initialization phase (which BeanNameAware is a part of).

    <bean id="myContext" class="org.springframework.context.support.ClassPathXmlApplicationContext">
    <property name="configLocation" value="myPackage/myBeans.xml"/>
    </bean>
    Juergen

  2. spring-projects-issues commented on Feb 4, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Kenny MacLeod commented

    Outstanding work as always. Thanks.

  3. added
    type: enhancement
    in: core
    on Jan 11, 2019
  4. added this to the 2.5.2 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions