Kevin
Kevin

Reputation: 25269

spring autowiring

Let's say I have some class X that is going to be injected all over the place (say 100+ other beans). There is only one instance of X, so it seems to make sense to autowire by type. I was hoping that I could do something like:

<bean id="xInstance" class="X" autowire="byType" />

And then have it magically autowired all over the place. Unfortunately, it seems like autowiring works in the opposite way, where I declare X without autowiring and then declare every OTHER bean to be autowired by type.

I don't really see what good this has done me, since now I have to modify any bean that might inject type X (i.e. hunting down N possible places where X is to be injected is exactly what I want to avoid). What I want is to mark the source bean as autowired (meaning it will be autowired into other beans) and have all target beans get magically wired. Is it possible?

Upvotes: 1

Views: 419

Answers (2)

ring bearer
ring bearer

Reputation: 20803

Auto wiring is per bean. Spring will resolve other beans for the current bean in question by inspecting BeanFactory. Implicit auto-wiring as you expect is an enhancement request

Upvotes: 2

Bozho
Bozho

Reputation: 597372

No, it isn't. You have to specify the details about injection in the injection target.

Upvotes: 0

Related Questions