0

I am java developer and I use your framework "Spring" in my application. I have a problem and I have not found clear answer on Spring official documentation and on any forum.

Problem description.

We have two classes:

public class A {
...
...
}


public class B {
private A a;

public void setA(A a) {
    this.a = a;
}

....
....
}

I want use dependency injection mechanism form Spring and inject class A to B when B is created. Class B is not managed by Spring, when I create class B I use new operator, I looked to Spring documentation and I have found @Configurable and AspectJ solution, it all work when I have access to source code of class B and I can put annotation

@Configurable
public class B {
....
....
}

My problem is, I don't have access to source code of class B (let say it comes from some outside library) and I can't put annotation @Configurable. Can I replace @Configurable by some XML definition in xml configuration file. I haven't found answer for that in Spring documentation (only @Configurable annotation example)

kriegaex
  • 63,017
  • 15
  • 111
  • 202

1 Answers1

0

Take a look at this SO question.

I would suggest that you use @Configurable as an absolutely last resort. It introduces complexity that in most cases can be avoided using regular Spring configuration.

Community
  • 1
  • 1
geoand
  • 60,071
  • 24
  • 172
  • 190