My application has a interface as below.
public interface MainInterface
{
void someMethod();
}
Then, i have number of implementations of this interface.
@Service
public class ImplClass1 implements MainInterface
{
@Override
public void someMehtod()
{
//Execution of code
}
}
@Service
public class ImplClass2 implements MainInterface
{
@Override
public void someMehtod()
{
//Execution of code
}
}
@Service
public class ImplClass3 implements MainInterface
{
@Override
public void someMehtod()
{
//Execution of code
}
}
Below is a controller.
@Controller
public class MainController
{
MainInterface implObj;
@RequestMapping("service1")
public void Service1Handler()
{
//Replace below with @Autowire
implObj = new ImplClass1();
}
@RequestMapping("service2")
public void Service1Handler()
{
//Replace below with @Autowire
implObj = new ImplClass2();
}
@RequestMapping("service3")
public void Service1Handler()
{
//Replace below with @Autowire
implObj = new ImplClass3();
}
}
As mentioned in comment of each method i want to initialize it using spring. This is just an example. In my real time application i have 12 implementations of a interface and 6 methods in a controller.
Can you please guide how can i use autowire feature at method level or suggest any other best way around.
Thanks