Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java接口(Springbean)返回的类中的方法_Java_Spring_Maven_Spring Mvc - Fatal编程技术网

使用java接口(Springbean)返回的类中的方法

使用java接口(Springbean)返回的类中的方法,java,spring,maven,spring-mvc,Java,Spring,Maven,Spring Mvc,我有一个控制器,它调用了如下所示的被选中的接口: class controllerA{ @Autowired public iService interfaceService; public void methodController(){ String param1 = new String("example1"); String param2 = new String("example2"); this.interfa

我有一个控制器,它调用了如下所示的被选中的接口:

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);
    }
}
我的界面是:

public interface iService {
    Class<T> getServiceA();
}
公共接口iSeries设备{
类getServiceA();
}
以及实施:

public class iServiceImpl implements iService {

    @Autowired      
    private ApplicationContext appContext;

    public class<T> getServiceA(){
        return appContext.getType("serviceA").cast(appContext.getBean("serviceA"));
    }
}
公共类iServiceImpl实现iService{
@自动连线
私有应用上下文appContext;
公共类getServiceA(){
返回appContext.getType(“serviceA”).cast(appContext.getBean(“serviceA”));
}
}
和applicationContext-service.xml(1):(已修复)


applicationContext-service.xml(2)更改了以下内容:

<bean id="serviceA" class="service.oracle.ServiceA"/>

这些xml随着maven概要文件在编译时的变化而变化

我的问题是不可能在控制器上调用serviceA.methodA(param1,param2),我使用不同的配置进行探测

上下文正确地注入bean,但是我如何在控制器上调用服务的方法呢

无法在接口上返回serviceA上实现的其他接口,因为该服务具有静态方法


谢谢

如果该方法返回一个
,那么您如何对其调用方法?!“因为服务有静态方法”<代码>静态method+Spring==在这一过程中出现了很大的问题。删除
static
方法并重新考虑您的设计。您的代码片段很奇怪:
iServiceImpl
类,其id为
iServiceFacade
,您可以在其中设置属性
p:serviceA ref=“serviceA”
,但是
iServiceImpl\getServiceA
检索bean类程序。这是工作代码吗?是的,FacadeImpl上的服务a是另一个探测器。我通过appContext.getBean(“serviceA”)获得bean,作为@BoristheSpider(删除静态方法)建议的替代方案,您还可以创建委托给静态方法的包装器类。通过这种方式,您可以创建实例,然后这些实例可以符合定义的接口(例如,
IServiceA
<bean id="serviceA" class="service.oracle.ServiceA"/>