我有一种我无法解释的情况。 我正在尝试创建一个将调用Spring服务的RMI服务器,但我无法将bean绑定到rmi注册表,因为它们都是空的。 代码是这样的:
.form-container input[type="reset"] {
// style here
}
Spring配置类是:
public class RMIServer {
private static final Logger LOG = LoggerFactory.getLogger(RMIServer.class);
public static void main(final String[] args) throws RemoteException, AlreadyBoundException {
final Registry registry = LocateRegistry.createRegistry(RmiConstants.RMI_PORT);
final ApplicationContext ctx = new AnnotationConfigApplicationContext(RmiConfiguration.class);
for (final String key : ctx.getBeansOfType(BaseRmi.class).keySet()) {
LOG.info("Registering {}...", key);
registry.bind(key, (BaseRmi) ctx.getBean(key));
}
LOG.info("RMI server was started...");
}
}
我要实例化的bean是:
@Configuration
@ImportResource({ "classpath*:app-context.xml" })
public class RmiConfiguration {
@Bean
AccountRmi accountRmi() {
try {
return new AccountRmiImpl();
} catch (final RemoteException e) {
return null;
}
}
}
public class AccountRmiImpl extends BaseRmi implements AccountRmi {
private static final long serialVersionUID = 5798106327227442204L;
private final static Logger LOG = LoggerFactory.getLogger(AccountRmiImpl.class.getName());
@Autowired
private AccountService accountService;
public AccountRmiImpl() throws RemoteException {
super();
}
@Override
public List<PersonType> getPersonTypes() throws AppException {
return accountService.getPersonTypes();
}
}
是:
BaseRmi
这个bean的接口是:
public abstract class BaseRmi extends UnicastRemoteObject {
protected BaseRmi() throws RemoteException {
super();
}
private static final long serialVersionUID = 9115163829282749718L;
}
public interface AccountRmi extends AccountFacade, java.rmi.Remote {
}
包含业务逻辑。
我看到的是,如果我删除了AccountRmi接口声明上的AccountFacade
接口,bean就会被实例化,但是我需要该接口来进行远程查找。日志中不会显示任何错误。 Spring是否对bean声明中的多个接口有限制,或者仅仅因为java.rmi.Remote接口?
如果要求,我可以提供进一步的细节。
非常感谢, 丹尼尔