Affects: 5.3.27


File: https://github.com/spring-projects/spring-framework/blob/main/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleInstantiationStrategy.java Spot: line 166

I was updating my Spring 3 project to Spring 5 when I ran into bizarre errors with my JRuby beans. In the past, creating them from separate application contexts kept their memory/variables separate from each other. Now class variables were being shared (this is normal Ruby behavior). In my case, this was resulting in strange crashes with huge stack traces. Eventually, I decided I had to dive into the source and was shocked when I read exactly what I needed to know in plain English.

"Circular reference involving containing bean, consider declaring the factory method as static for independence from its containing instance. "

I had not created a circular reference, so I didn't receive this message. However, I very much needed to know that my beans were not independent from their containing instance.

Please consider changing the if statement and making the message slightly more general so more people can benefit from this important information.

Comment From: snicoll

Thanks for the report but, before changing any code or documentation, we need to better understand the problem. You're saying you have not created a circular reference, but you're not showing the code either so it's very hard for us to asses what went wrong.

If you want support, please take the time to share a small sample that reproduces the problem you've described. You can attach a zip to this issue or push the code to a GitHub repository.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: 4pins

You requested a minimal example in an environment that would include a complete Java project, Spring Beans, and JRuby scripts. Do you have guidelines around how to do this or a way to narrow down what is needed?

Maybe I could pull together the JRuby that causes this along with explanation?

Comment From: snicoll

I don't have any specific guidelines but this being related to JRuby doesnt help obviously.

Comment From: 4pins

So the problem stems from JRuby having shared class variables (indicated by starting with @@). I encountered the problem by having two instances of a class with at least one of these shared variables going at the same time. In Spring 3 using diffrent application contexts with statically scoped beans kept these separated. In Spring 5 it doesn't, but it isn't a circular reference it is a parallel one. So I didn't get the incredibly helpful additional information in the exception.

Obviously I am good to go, I am just hoping to help others.

Comment From: snicoll

Obviously I am good to go, I am just hoping to help others.

Thanks, but without a way for us to investigate the problem, I can't justify spending more time on this. Spring 3 was released almost 15 years ago and Spring 5 is in maintenance mode.