내 응용 프로그램은 아래와 같은 인터페이스를 가지고 있습니다.스프링 자동 와이어 메서드 내
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 메서드가 있습니다.
방법 수준에서 자동 배선 기능을 사용하거나 다른 최상의 방법을 제안 할 수있는 방법을 안내해주십시오.
감사
내가 컨트롤러 sigletone이 될 것이라고 우려하고 당신은 당신의 인터페이스를 만들었습니다 컨트롤러의 인스턴스이며 각 메소드에서 구현을 변경하려고합니다. –
네, 맞습니다. –