将基于注释的配置转换为XML

时间:2014-08-19 08:33:30

标签: java spring xml-configuration

如何在XML中编写基于注释的这部分配置?

@Bean
public EventRepository eventRepository() throws Exception {
    return new SolrRepositoryFactory(eventTemplate())
        .getRepository(EventRepository.class, new EventRepositoryImpl(eventTemplate()));
}

此配置的完整代码:

@Configuration
public class SolrContext {

    @Bean
    public SolrServerFactory solrServerFactory() {
        return new MulticoreSolrServerFactory(new HttpSolrServer("solr.host"));
    }

    @Bean
    public SolrTemplate eventTemplate() throws Exception {
        SolrTemplate solrTemplate = new SolrTemplate(solrServerFactory());
        solrTemplate.setSolrCore("events");
        return solrTemplate;
    }

    @Bean
    public EventRepository eventRepository() throws Exception {
        return new SolrRepositoryFactory(eventTemplate())
            .getRepository(EventRepository.class, new EventRepositoryImpl(eventTemplate()));
    }
} 

我从that回答中得到了这个例子。

0 个答案:

没有答案