我想搞乱RMI而且我遇到了一些问题。我想在我的自定义类中使用远程方法,但我不知道如何将bean传递给类变量。 RMI连接本身似乎工作正常。我的代码是:
//Application start class
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
@Bean
RmiProxyFactoryBean searchService() {
RmiProxyFactoryBean rmiSearchServiceBean = new RmiProxyFactoryBean();
rmiSearchServiceBean.setServiceUrl("rmi://127.0.0.1:1199/searchService");
rmiSearchServiceBean.setServiceInterface(SearchService.class);
return rmiSearchServiceBean;
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Component
public class RmiSearchContext {
@Bean
RmiProxyFactoryBean searchService() {
RmiProxyFactoryBean rmiSearchServiceBean = new RmiProxyFactoryBean();
rmiSearchServiceBean.setServiceUrl("rmi://127.0.0.1:1199/searchService");
rmiSearchServiceBean.setServiceInterface(SearchService.class);
return rmiSearchServiceBean;
}
}
//My custom class where I want to make remote method call
@Component
public class BasicSearchQuery {
private long id;
private String content;
//This is a variable for the Bean
@Autowared
private SearchService searchService;
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
public String getContent() {
return this.content;
}
public void setContent(String content) {
this.content = content;
}
public SearchService getSearchService() {
return this.searchService;
}
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
}
public List<BasicSearchResults> execute() {
// Here i want to do a remote method call
return this.searchService.getSearchResults(this.id, this.content));
}
}
如果不使用context.xml文件,有没有办法做到这一点?