sling taglib를 사용하여 jsp에서 서비스 객체를 인스턴스화하려고합니다. 일반 시나리오에서는 서비스 클래스는 한 클래스는 아주 간단합니다 의해 구현되는 위치 - SlingScriptHelper # getService() 메소드를 사용하여 OSGi 서비스 필터링
RegistrationService registrationService = sling.getService(RegistrationService.class);
그러나 서비스 클래스는 1 개 이상의 구현 클래스를 가지고 있다면, 어떻게 우리가에 대한 개체를 인스턴스화해야합니다 수 있습니다
특정 클래스.내 자바 클래스 등이있다 : -
1. 인터페이스 : RegistrationService
2. 구현 클래스 1 : -
@Properties({@Property(name = "datasource", value = "SBWS"})
@Service
public class RegistrationServiceImpl implements RegistrationService{
}
3. 구현 클래스 2 : -
@Properties({@Property(name = "datasource", value = "SOLR"})
@Service
public class RegistrationServiceImpl implements RegistrationService{
}
사용 방법을 확인하려면 어떻게해야합니까?
OSGi 서비스를 받기와 속성을 통해 필터링RegistrationService[] services = sling.getService(RegistrationService.class, "(datasource=SBWS)");
if (services.length > 0) {
// services[0] contains your service
}
매우 낮은 수준이다하자에 대한 서비스의 인스턴스를 JSP에서
(210)는 필터를 지정할 수 있도록 구현 클래스 1
깨끗한 방법이 있는지 확실하지 않지만 RegistrationService 인터페이스를 확장하는 두 개의 다른 인터페이스가있는 방법에 대해 알고 싶습니다. @Services 주석에서 여러 개의 인터페이스를 정의 할 수 있지만 jsp에서는 특정 인터페이스로 필요한 인터페이스를 선택할 수 있습니다. – Thomas