Reputation: 1
Does Spring
supports Interface Injection completely
?
From “Martin Fowler” Blog it was mentioned that a component that depends on a bean needs to implemented as an Interface
that injects Bean
.
When we consider this scenario it will be possible BeanNameAware
, XXXAware Interfaces
that injects appropriate bean object.
Is it possible to inject userdefinedd
Beans using Interface Injection
other than spring supplied classes.
I am confused with all the above.
Upvotes: 0
Views: 877
Reputation: 121212
It is correct and canonical concept.
You rely on contract (interfaces) and inject them, but container takes care of their implementations:
public interface MyService {}
public class MyServiceImpl implements MyService {}
<bean id="myService" class="com.my.proj.MyServiceImpl"/>
public class MyController {
@Autowired
private MyService service;
}
Don't mix contaier components and its API (*Aware
) and user-defined application components.
Upvotes: 1