Closed
Description
With a project from start.spring.io
.
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import jakarta.annotation.PostConstruct;
@SpringBootApplication
public class DemoApplication {
public static class Base {
public Base() {
System.err.println("Class of type " + getClass().getSimpleName() + " created");
}
public Base(Base[] otherBases) {
this();
System.err.println("This constructor should not run");
}
}
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public static class Other extends Base {
}
@Autowired
private ApplicationContext context;
@PostConstruct
public void init() {
Base object = context.getAutowireCapableBeanFactory().createBean(Base.class);
System.err.println("Bean factory returned bean of type " + object.getClass().getSimpleName());
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Expected output, as with version 6.0.4 / Spring Boot 3.0.2
Class of type Base created
Bean factory returned bean of type Base
Actual output with 6.0.5 / Spring Boot 3.0.3
Class of type Other created
Class of type Base created
This constructor should not run
Bean factory returned bean of type Base