Spring:正确设置@ComponentScan

The*_*ect 6 spring components rmi spring-remoting applicationcontext

我有以下设置为我的Spring Application Context.


@Configuration
public class RmiContext {
@Bean
    public RmiProxyFactoryBean service() {
        RmiProxyFactoryBean rmiProxy = new RmiProxyFactoryBean();
        rmiProxy.setServiceUrl("rmi://127.0.1.1:1099/Service");
        rmiProxy.setServiceInterface(Service.class);
        return rmiProxy;
    }
}


@Configuration
public class LocalContext {
@Bean
    public Controller Controller() {
        return new ControllerImpl();
    }
}


@Configuration
@Import({RmiContext.class, LocalContext.class})
public class MainContext {

}

上面的设置工作正常,但我想启用@ComponentScan注释Controller,@Component因为Controller我的应用程序中有很多s,当逐个声明时使用是很乏味的@Bean.


@Configuration
@ComponentScan(basePackageClasses = {Controller.class})
public class LocalContext {
    /* ... */
}
问题是,当我这样做时@ComponentScan(basePackageClasses = {Controller.class}),以前的精细工作RmiProxyFactoryBean无法识别或无法创建.

那么,如何配置my MainContext以便通过RMI和本地bean创建两个bean?