Injecting beans into a class outside the Spring managed context

I'm an end-user of one of my company's products. It is not very suitable for integration into Spring, however I am able to get a handle on the context and retrieve the required bean by name. However, I would still like to know if it was possible to inject a bean into this class, even though the class is not managed by Spring itself.

Clarification: The same application which is managing the lifecycle of some class MyClass, is also managing the lifecycle of the Spring context. Spring does not have any knowledge of the instance of MyClass, and I would like to some how provide the instance to the context, but cannot create the instance in the context itself.


You can do this:

ApplicationContext ctx = ...
YourClass someBeanNotCreatedBySpring = ...
    AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);

You can use @Autowired and so on within YourClass to specify fields to be injected etc.

Need Your Help

My Binary Tree's delete function occasionally results in duplicate entries

haskell binary-search-tree

I created a small Binary Tree "library", but tDelete isn't functioning properly in certain circumstances. I tested it on simpler trees and it worked fine, but in this particular scenario, it causes a

How negligible is the time for ofstream

c++ time ofstream

I have a C++ program where I do various experiments and during these experiments I output some values to a file using ofstream. The structure is basically:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.