编程语言
首页 > 编程语言> > 将基于Java的配置转换为基于Spring的XML

将基于Java的配置转换为基于Spring的XML

作者:互联网

我正在尝试将在java注释中完成的Birt应用程序转换为基于XML,但是“我很难将此部分更改为xml”

@Bean   
public BirtViewResolver birtViewResolver() throws Exception {
    BirtViewResolver bvr = new BirtViewResolver();
    bvr.setBirtEngine(this.engine().getObject());
    bvr.setViewClass(HtmlSingleFormatBirtView.class);
    bvr.setDataSource(this.birtDataServiceConfiguration.dataSource());
    bvr.setReportsDirectory("Reports");
    bvr.setOrder(2);
    return bvr;
}

我尝试了这个,但无法弄清楚如何设置birtEngine,viewClass和dataSource部分

<beans:bean id="birtViewResolver" class="org.eclipse.birt.spring.core.BirtViewResolver">
        <beans:property name="birtEngine" value="?" />
        <beans:property name="viewClass" value="?" />
        <beans:property name="dataSource" value="?" />
        <beans:property name="reportsDirectory" value="Reports" />
        <beans:property name="order" value="2" />
    </beans:bean>

先感谢您

解决方法:

鉴于这种

bvr.setBirtEngine(this.engine().getObject());

我将假设engine()是另一个返回FactoryBean对象的@Bean方法.在XML中,您可以将其作为

<bean name="engine" class="com.example.EngineFactoryBean" />

对于

bvr.setViewClass(HtmlSingleFormatBirtView.class);

Spring可以在XML中将完全限定的类名称作为字符串值转换为运行时的Class实例.

对于

bvr.setDataSource(this.birtDataServiceConfiguration.dataSource());

我将假设birtDataServiceConfiguration是对@Autowired的另一个@Configuration类的引用,dataSource()是在该类中声明的@Bean方法.

生成的XML声明就像

<!-- Assuming you converted that config to XML as well -->
<import resource="classpath:birtDataServiceConfiguration.xml" /> 
<beans:bean id="birtViewResolver" class="org.eclipse.birt.spring.core.BirtViewResolver">
    <beans:property name="birtEngine" ref="engine" />
    <!-- You would have to give the class' fully qualified name -->
    <beans:property name="viewClass" value="com.example.fully.qualified.HtmlSingleFormatBirtView" />
    <!-- Assuming that imported config had a bean declared with the name 'dataSource' -->
    <beans:property name="dataSource" ref="dataSource" />
    <beans:property name="reportsDirectory" value="Reports" />
    <beans:property name="order" value="2" />
</beans:bean>

标签:java,spring-mvc,xml,spring,birt
来源: https://codeday.me/bug/20190624/1277810.html