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.

Answers


You can do this:

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

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


Need Your Help

ASP.NET ModalPopup does not execute code

asp.net modalpopupextender

Wwhen I click the button on the popup to insert data to database, it does nothing, WHYYYYY?

Oxite or S#arp Architecture for new Asp.net CMS site

asp.net-mvc nhibernate content-management-system s#arp-architecture oxite

I'd like to build a CMS site based on Asp.Net Mvc and I want to choose my starting point.