私のアプリケーションには、以下のようなインターフェースがあります。
public interface MainInterface
{
void someMethod();
}
次に、このインターフェイスの実装がいくつかあります。
@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
}
}
下はコントローラーです。
@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();
}
}
各メソッドのコメントで述べたように、春を使用して初期化したいと考えています。これはほんの一例です。私のリアルタイム アプリケーションでは、コントローラーに 12 のインターフェイスと 6 つのメソッドを実装しています。
メソッドレベルで自動配線機能を使用する方法を教えてください。または、他の最善の方法を提案してください。
ありがとう