Comments (5)
You should not mutate the type of a bean in a BeanPostProcessor
in the first place. Bean post processing is meant to eventually wrap the target instance as hinted by the Javadoc:
The returned bean instance may be a wrapper around the original.
If you mutate the type, then you're exposing yourself to the issue you've described, with changing the bean dependency graph is a way to get things working as the container will have the effective type to match against.
from spring-framework.
Thank you for the clarification.
FWIW "wrapper" is a broad term, by no means limited to "the same type as the wrapped element". Wrappers can be used for encapsulation, extension, as Facades or whatever the developer's heart desires. Perhaps it's worth mentioning in the docs explicitly that the wrapper (if used) must have the original bean's type signature in its inheritance hierarchy. Is it perhaps possible to enforce this by using the same generic type in the BPP's method's argument and a return type instead of a wildcard Object
?
from spring-framework.
You are mistaken. I already mentioned above that the type you return can be restricted, or can be expanded so that generic type idea makes no sense.
FWIW "wrapper" is a broad term, by no means limited to "the same type as the wrapped element".
Where did I say that a wrapper has to be the same type as the wrapper element (since you seem to be quoting something)? Perhaps looking at a class in the JDK might help?
BeanPostProcessor
is a low-level contract so we need to provide the flexibility as a framework. If you decide to return a completely different hierarchy for a bean, so be it but then don't complain if wiring has the side effect you've experienced is all I am saying.
I think the issue has run its course now.
from spring-framework.
The returned bean instance may be a wrapper around the original
Does that mean the wrapper must be of the same type as the initial bean? The docs don't specify this explicitly
from spring-framework.
Like any wrapper in Java, I am assuming you're familiar with the concept. It could be an interface of the bean, or it could implement an additional interface or something like that.
The original point is that if you have a bean of type A and then replace it with a bean of type B and then expect to be able to inject a bean of type B, you are misusing the API as indicated by the Javadoc excerpt I've shared.
from spring-framework.
Related Issues (20)
- Remove unneeded `@SuppressWarnings("NullAway")` HOT 1
- Indicate since what SF is possible declare @Transactional in an interface HOT 1
- @RequestBody decorator is crashing on Json.Parse for null types - null types are from Google Firebase response stream. HOT 1
- No support for SOAP webservices in 6.x HOT 1
- SpEL containing argument references not working from Spring boot 3.2.X and even after 3.2.3 HOT 3
- Remove unnecessary `method.isAccessible()` invocation
- Maximum Request Size handling support for Undertow in StandardMultipartHttpServletRequest HOT 1
- CoroutinesUtils causes ClassCastException & NullPointerException after upgrading to Spring 6.1.5 / Spring Boot 3.2.4 HOT 4
- MvcUriComponentsBuilder.fromMethodName does not pick the annotated method transparently HOT 6
- Support new Hooking Point. HOT 6
- Transactional annotation breaks AOT for native image HOT 2
- hibernate isolation property `release_mode` -> on_close not working HOT 2
- StringUtils.truncate(Charsequence, int) incorrect length size HOT 1
- The parameter validation of the PropertyAccessiorFactory.forBeanPropertyAccess method is incomplete. HOT 2
- Implicitly introduced beans and explicitly introduced beans coexist, and the implicitly introduced beans are deleted. HOT 1
- Allow custom ScheduledTaskObservationConvention in ScheduledMethodRunnable HOT 4
- Upgrade to webjars-locator-lite 1.0.0
- Deprecate bean definition overriding
- Upgrade to Gradle 8.7
- Upgrade to Gradle 8.7 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.