Use method from class returned by interface java (spring bean) -


i have controller,that call inyected interface this:

class controllera{     @autowired     public iservice interfaceservice;      public void methodcontroller(){         string param1 = new string("example1");         string param2 = new string("example2");         this.interfaceservice.getservicea().methoda(param1,param2);     } } 

well, interface is:

public interface iservice {     class<t> getservicea(); } 

and implementation:

public class iserviceimpl implements iservice {      @autowired           private applicationcontext appcontext;      public class<t> getservicea(){         return appcontext.gettype("servicea").cast(appcontext.getbean("servicea"));     } } 

and applicationcontext-service.xml (1): (fixed)

<bean id="iservicefacade" class="service.facade.iserviceimpl"/>  <bean id="servicea" class="service.postgres.servicea"/> 

and applicationcontext-service.xml (2) change this:

<bean id="servicea" class="service.oracle.servicea"/> 

these xml change maven profile on compile time.

my problem it's not possible call servicea.methoda(param1, param2) on controller , probe distinct configuration.

the context inject bean correctly, how call method of service on controller?

it's not possible return on interface other interface implemented on servicea, because service have static method...

thanks!


Comments