通过grails中的自定义报告上下文连接spring bean

时间:2011-10-12 21:22:49

标签: spring grails jasper-reports context.xml

我正在使用基于Grails的Web应用程序的Jasper Reports,我有一个ReportingContext.xml,每个报告都有bean,例如报告ID /名称映射与报告模板(jrxml)。我需要了解配置和设置上下文xmls的基本步骤,以及如何在应用程序启动时将它们加载到我的reportscontroller中。

旧的应用程序在java / j2ee中使用了这个报告xml。我们必须在grails上开发一个类似的系统。

大多数上下文包含报告名称映射的jrxml,但我无法理解上下文中的某些bean。

以下是报告context.xml的示例内容,适用于1个报告

 <beans> 
            <!-- ========================= REPORTING SERVICE WRAPPER ========================= -->
             <bean parent="baseTransactionProxy" name="myReportingService"> 
             <property name="proxyInterfaces" value="com.pack.my.reporting.service.myReportingService"/> 
             <property name="transactionAttributes">
                 <property name="target"> 
             <bean parent="baseServiceSupport" class="com.pack.my.reporting.service.impl.myReportingServiceImpl"> 
             <property name="reportManager" ref="reportManager"/> 
             <property name="mySecurityService" ref="mySecurityService"/> 
             <property name="businessUnitService" ref="businessUnitService"/> 
             </bean> 
             </property> 
             </bean> 
             <bean class="com.pack.my.reporting.manager.impl.ReportManagerImpl" id="reportManager"> 
             <property name="reportRenderers"> 
             <map> 
             <entry key="JasperPrint">
                 <entry key="siemJasperPrint">
             </map>
             </property>
             <property name="reportDefinitionDao" ref="reportDefinitionDao"/> 
             <property name="reportDao" ref="reportDao"/> 
             <property name="sequenceGeneratorService" ref="sequenceGeneratorService"/> 
             <property name="reportLocation" value="file:${my_HOME}/reports"/> 
             <property name="reportDefinitions">
                 <map> 
                 <entry key="businessUnitRoles"> 
                 <ref local="businessUnitRoles"/> 
                 </entry>
                 <entry key="businessUnitRoleUsers"> 
                 <ref local="businessUnitRoleUsers"/> 
                 </entry>
                 </map>
             </property>
             <property name="parameterPromptCodeMap">
                 <bean class="org.apache.commons.collections.map.CaseInsensitiveMap"> 
                 <constructor-arg> 
                 <map> 
                 <entry value="1" key="businessUnit"/> 
                 <entry value="1" key="businessUnitKey"/> 
                 <entry value="2" key="globaluser"/> 
                 <entry value="2" key="USERID"/> 
                 <entry value="2" key="USER_ID"/> 
                 <entry value="2" key="GLOBALUSERKEY"/> 
                 <entry value="3" key="identityCertification"/> 
                 <entry value="3" key="CERTIFICATIONID"/> 
                 <entry value="3" key="CERTIFICATION_ID"/> 
                 <entry value="4" key="startDate"/> 
                 </map> 
                 </constructor-arg> 
                 </bean> 
                 </property>
             </bean> 
            <!--- Report Groups Business Unit reports Group 1 Users reports -->
             <bean class="com.pack.my.reporting.domain.ReportDefinition" id="businessUnitRoles">
                 <property name="reportName" value="Business Unit Roles Report"/> 
                 <property name="reportFiles"> 
                 <map> 
                 <entry value="BusinessUnitRoles.jrxml" key="JasperPrint"/> 
                 </map> 
                 </property> 
                 <property name="promptForBusinessUnit" value="true"/> 
                 <property name="reportGroup" value="1"/> 
                 <property name="displayName" value="report.businessUnitRoles.name"/>
             <bean class="com.pack.my.reporting.domain.ReportDefinition" id="businessUnitUsers">

             </bean>
            </beans>

1 个答案:

答案 0 :(得分:1)

  1. 将依赖项添加到grails-app / conf / BuildConfig.groovy
  2. 将上述文件复制到/grails-app/conf/spring/resources.xml
  3. 阅读Grails and Spring - Reference Documentation
  4. 不再构建resources.xml,因为spring目录中只存在resources.groovy。只需将spring上下文文件复制到resources.xml。