Exporting a lazily initialized bean (which implements SelfNaming and is annotated with ManagedResource annotation) gives IllegalStateException [SPR-17592] #22124
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: regression
A bug that is also a regression
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Lavish Kothari opened SPR-17592 and commented
I'm having a bean that is
ManagedResource
SelfNaming
I'm exporting it using spring's
AnnotationMBeanExporter
.All this works good when I'm using spring version
4.3.16.RELEASE
, but when I upgraded my spring version to5.0.5.RELEASE
or5.1.3.RELEASE
this code started giving meIllegalStateException
.My Bean definition and the spring's context.xml looks like this:
SampleBean.java
application-context.xml
I understand that an extra validation was added here, and this is causing
IllegalStateException
but I'm not completely sure why that was added.The stack-trace looks like this:
My experiments:
SampleBean
, I don't get thisIllegalStateException
.ManagedResource(objectName = "com.jmx.trial:name=sampleBean")
and makeSampleBean
not implementSelfNaming
interface, again I don't getIllegalStateException
MBeanExporter
andCGLibAopProxy
I don't get this exception. (This is specifically interesting that in debug-mode the tests run successfully but in normal run mode the tests fails.)Though not very sure, but I think implementing
SelfNaming
interface is not a very good idea as the javadocs ofSelfNaming
interface says that:I'm not sure if it is the problem with using
SelfNaming
interface or I'm doing something fundamentally wrong. Can you please explain this behavior and point me to the fundamentals that I'm missing.PS: some of my findings: (might be unrelated) From here I found this caution point:
I don't completely understand this, but is this the rule that I'm violating?
I feel that the
Assert.state
that is getting called inpostProcessTargetObject
should be moved into the methodinjectNotificationPublisherIfNecessary
and should be called only ifmanagedResource instanceof NotificationPublisherAware
istrue
.Affects: 5.0.5, 5.1.3
Reference URL: https://stackoverflow.com/questions/53711613/exporting-a-lazily-initialized-bean-which-implements-selfnaming-and-is-annotate
Attachments:
Issue Links:
Referenced from: commits e95c1b3, 2c98c1b
Backported to: 5.0.12
The text was updated successfully, but these errors were encountered: