Birt的数据源可以用多种形式,当我们把BIRT嵌入到现有系统时,一般想读取现有系统的数据库配置。那么怎样读取呢,配置如下:
建议脚本数据源。然后在beforeOpen中加入如下代码:
importPackage(Packages.org.springframework.context.support);//引用Spring类 importPackage(Packages.org.apache.commons.dbcp);//应用Datasource类 var ctx = new ClassPathXmlApplicationContext("birt-context.xml");//读取Spring配置文件 var dataSource = ctx.getBean("dataSource");//读取DataSource extensionProperties.odaURL = new String(dataSource.getUrl());//读取Url并赋值 extensionProperties.odaUser = new String(dataSource.getUsername());//读取Username并赋值 extensionProperties.odaPassword = new String(dataSource.getPassword());//读取Password并赋值
其中birt-context.xml里面有现有系统的数据库配置