Skip to content

Error in JavaConfig sample code - Paragraph 3.11.2.2 Building the container programmatically [SPR-6638] #11304

@spring-projects-issues

Description

@spring-projects-issues

Gildas Cuisinier opened SPR-6638 and commented

In http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-java-instantiating-container-register :

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(AppConfig.class, OtherConfig.class);
    ctx.register(AdditionalConfig.class);
    ctx.refresh();
    MyService myService = ctx.getBean(MyService.class);
    myService.doStuff();
}

The register method is defined on AnnotationConfigApplicationContext and not ApplicationContext interface.

The code must be :

public static void main(String[] args) {
    AnnotationConfigApplicationContext = new AnnotationConfigApplicationContext();
    ctx.register(AppConfig.class, OtherConfig.class);
    ctx.register(AdditionalConfig.class);
    ctx.refresh();
    MyService myService = ctx.getBean(MyService.class);
    myService.doStuff();
}

Affects: 3.0 GA

Referenced from: commits f7b0a2c

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions