gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 02:06:19 26 4
gpt4 key购买 nike

我正在尝试将使用 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 是对另一个 @Configuration 类的引用,您有 @AutowireddataSource () 是在该类中声明的 @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 - 将基于 Java 的配置转换为基于 Spring XML 的配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25091221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com