Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

There is any open source generic bean container? Let me explain the scenario. I

ID: 661081 • Letter: T

Question

There is any open source generic bean container?

Let me explain the scenario.

I am working in a Java EE project, and we are using a Swing client. We are using Json to serialize objects. In client side we can recieve a Json message representing a List. Sometimes some A instances can be the same object, but actually for 2 instances of A that are the same object we construct 2 beans that are equals between them but aren't the same instance. This give us some problems: memory overhead, changes made to one instance don't update the other one, ...

What i think we need is a container that can make instance wiring, when a new instance is contructed we should check if it already exist in the container, in that case assign it instead the constructed one. Somethig like JPA L2 cache, but in client side.

Is there any implementation about it? Or maybe i should use another approach?

Explanation / Answer

You might want to try HK2 (http://hk2.java.net). It has things like Singleton scope for those "Bean" instances that should only be there once and things like PerLookup for things that should get created every time they are looked up for or injected. Furthermore, it works well in the JavaSE environment, and even has provisions for things like security in that environment (which other frameworks like this often overlook).

It is a lot like CDI, except that it was designed from the ground up to work in JavaSE.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote