Comments (3)
Thanks for the report. I can see that the BeanFactory
indeed calls the default constructor of CommandExample
albeit being provided with the integer argument.
The resolution of the constructor is highly dynamic and AOT cannot detect this pattern at build time. I had hoped that providing the necessary reflection hints would fix it but it does not work and will need some further investigation.
from spring-framework.
So it turns out that the code path of this method does not ignore an instance supplier if one is defined. This explains why the default constructor is invoked albeit a matching argument being provided.
Please note that creating a bean like this is not idiomatic Spring and we won't be able to infer the necessary hints as we can't detect at build time that this constructor is going to be invoked by reflection.
from spring-framework.
I didn't seen something on documentation, I hope it is my mistake.
Yes and no. There was definitely a bug that we used an instance supplier even in the case getBean
was used with custom arguments. So I fixed that but the whole thing is a bit strange with AOT/native.
The instance supplier is used to apply the optimizations we've discovered at build-time. Typically, the autowiring on the field in CommandExample
is processed there, rather than discovering things at runtime. The pattern you've used means that you'd like to instantiate the bean in a custom manner. This has two consequences:
- We don't know the constructor you're going to invoke as the arguments are in your own code with no way to discover them. As such, the sample with this fix would not work until you add some reflection hint for the constructor that takes the
Integer
argument. - Now that the instance supplier is discarded, the autowiring is no longer applied and that field is null.
Looking at your simplified example, I wonder if CommandExample
has to be a bean. IMO it would be better to provide the service and the integer to the constructor, and resolve the service in your controller. I am sure your actual code is more involved but not making it the command a bean is something you should be pursuing for native compatibility. In particular, getBean
with arguments is not recommended. I've created #32690 to document that bit.
from spring-framework.
Related Issues (20)
- Limit reflective operations in `BeanInstanceSupplier` with Spring AOT
- Unify Spring Framework documentation
- Introduce API to initialize `BeanFactory` before singleton instantiation
- Have HandlerInterceptor being ScopedValue friendly
- Spring AOP fails against registered `@Configurable` aspect HOT 7
- Spring AOP fails against registered `@Configurable` aspect HOT 1
- Spring AOP fails against registered `@Configurable` aspect HOT 1
- Reactor Context not propagated from Mono to other Reactive implementation when adapting using ReactiveAdapterRegistry HOT 1
- Missing hints for org.hibernate.generator.Generator HOT 3
- Refine CDS documentation
- `LocalValidatorFactoryBean` does not define or inherit an implementation of the resolved method `forExecutables` HOT 2
- use Hibernate automatic Dialect resolution HOT 1
- Introduce getRequest and getResponse on MvcTestResult
- MockHttpServletRequest should not use a shared reader when no content is available HOT 1
- MockHttpServletRequest should not use a shared reader when no content is available HOT 1
- Spring Framework 6.2.x EOS timeline HOT 1
- Suppress deprecation warning for AOT-generated code that refers to a deprecated bean type
- Avoid creation of SAXParserFactory for every read operation in Jaxb2Marshaller and co HOT 2
- Upgrade "spring-aop" from 6.1.6 to 6.1.7 yields 'error Type referred to is not an annotation type: Configurable' HOT 2
- Avoid creation of SAXParserFactory for every read operation in Jaxb2Marshaller and co HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-framework.