I have a requirement wherein I define a contract in Spring project and want to autowire an external JAR during deploy that implements the contract (set of interfaces). I do not want to enforce the external JAR to be Spring-dependent so that it is as flexible as possible. Is it not possible in my Spring project to use the classes from external JAR as autowire substitutions wherever I am using my contract interfaces? Let me explain with an example:
Spring project:
@Controller
public class MyController {
@Autowired
private MyInterface interface;
}
Now the JAR implementing the contract interfaces may be provided by client and I may not know the package names before hand and it could even be a non-Spring project, so it may not be declared with @Component annotation.
e.g.
public class CustomerClass implements MyInterface {
}
Now in my spring project, is there a way to inject CustomerClass in place of MyInterface? I hope my question is clear.
Thanks
@Paddy,
Regarding to your concern about whether you can traditional XML way to achieve the same goal. The following is a sample code showing how to achieve it. Note: the interface MyInterface cannot be dynamic in this way, because the controller is holding a refernece to MyInterface .
Spring application context config :
MyInterface and two different implementation class
test.properties file under classpath(you can use ant script and maven profile to change property value)
web layer Controller (you can inject the implementation class based on dynamic bean candidate)