DynamicJasper与Struts 2集成错误

时间:2014-04-16 12:03:56

标签: java maven struts2 jasper-reports dynamic-jasper

我正在尝试在我的项目中将DynamicJasper报告与Struts2集成。 Strut2(使用XWork 2.2.1 jar)已经在使用JasperReports(版本4.7.1)。根据{{​​3}}我添加了DynamicJasper(版本5.0.0),对于Struts 2集成,将依赖关系DynamicJasper-Struts2(版本1.3)添加到最新版本。

执行期间抛出以下错误

org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path [/proj] threw exception [Filter execution threw an exception] with root cause
java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/Object;)Ljava/lang/Object;
    at ar.com.fdvs.dj.struts2.DJStruts2Result.doExecute(DJStruts2Result.java:138)
    at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

在浏览时,我遇到了这个功能请求Struts 2.1.6兼容性(official dynamic jasper reports documention)已经关闭,我相信这是我项目中的问题,其中说

  

Xwork在版本2.1.2中更改了方法签名,我们重新编译了源代码   对于那个版本。

为了更清晰,以下是我的代码和依赖关系:

pom.xml

<repository>
  <id>fdvsolution.public</id>
  <url>http://archiva.fdvs.com.ar/repository/public1/</url>
</repository>

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-spring-plugin</artifactId>
    <version>2.1.8</version>
</dependency>
<dependency>
    <groupId>org.apache.struts.xwork</groupId>
    <artifactId>xwork-core</artifactId>
    <version>2.2.1</version>
</dependency>
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.1.8</version>
</dependency>
<dependency>
    <groupId>net.sf.jasperreports</groupId>
    <artifactId>jasperreports</artifactId>
    <version>4.7.1</version>
</dependency>
<dependency>
    <groupId>ar.com.fdvs</groupId>
    <artifactId>DynamicJasper</artifactId>
    <version>5.0.0</version>
</dependency>
<dependency>
    <groupId>ar.com.fdvs</groupId>
    <artifactId>DynamicJasper-Struts2</artifactId>
    <version>1.3</version>
</dependency>

struts.xml

<result-types>
    <result-type name="jasper" class="com.orgn.appl.util.JasperReportsResult" />
    <result-type name="dynamic-jasper" class="ar.com.fdvs.dj.struts2.DJStruts2Result" />
</result-types>

<action name="actnReport" class="reportAction" method="actnReport">
    <result name="success" type="tiles">reports.tiles</result>
    <result name="allReport">reports/allReport.jsp</result> 
    <result name="showDynaReport" type="dynamic-jasper">
        <param name="dynamicReport">myDynamicReport</param>
        <param name="layoutManager">classic</param>
            <param name="parameters">paramMap</param>
        <param name="contentType">text/html</param>
        <param name="format">HTML</param>
    </result>   
</action>

在我的动作课中,我有

// with getters and setters
private DynamicReport myDynamicReport = new DynamicReport();
private Map paramMap = new HashMap();

public String actnReport() throws ColumnBuilderException, JRException, ClassNotFoundException{

        LOG.debug("showDynaReport");

        myDynamicReport = DynamicJasper.myReport(); //I am getting the dynamic Report object from here
        LOG.debug("myDynamicReport----->"+myDynamicReport.getReportName());

        Object[] obj = new Object[3];
        obj[0] = new DynamicDemoBean(
                100.00f,
                "San Jose",
                200,
                "Tojo",
                "Vintage 2000",
                50,
                "CA",
                "Tojo is a finer variety of wine produced from the California wine yards. It has been produced to the industry standards. Tojo is a finer variety of wine produced from the California wine yards. It has been produced to the industry standards.");

        obj[1] = new DynamicDemoBean(
                110f,
                "San Jose",
                120,
                "Spinster",
                "Vintage 2000",
                50,
                "CA",
                "Spinster is a finer veriety of wine produced from the California wine yards. It has been produced to the industy standards.");

        obj[2] = new DynamicDemoBean(
                120.00f,
                "Down Town",
                220,
                "Royal",
                "Vintage 2000",
                50,
                "CA",
                "Royal is a finer veriety of wine produced from the California wine yards. It has been produced to the industy standards.");

        paramMap.put(0, obj[0]);
        paramMap.put(1, obj[1]);
        paramMap.put(2, obj[2]);


        LOG.debug("paramMap----->"+paramMap.size());
        return "showDynaReport";
    }

创建myDynamicReport的实际类如下所示,从Word按http://sourceforge.net/p/dynamicjasper/feature-requests/4/引用如下

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRPrintPage;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;
import net.sf.jasperreports.engine.export.JExcelApiExporterParameter;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import ar.com.fdvs.dj.core.DynamicJasperHelper;
import ar.com.fdvs.dj.core.layout.ClassicLayoutManager;
import ar.com.fdvs.dj.domain.DynamicReport;
import ar.com.fdvs.dj.domain.ImageBanner;
import ar.com.fdvs.dj.domain.Style;
import ar.com.fdvs.dj.domain.builders.ColumnBuilder;
import ar.com.fdvs.dj.domain.builders.ColumnBuilderException;
import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
import ar.com.fdvs.dj.domain.constants.Border;
import ar.com.fdvs.dj.domain.constants.Font;
import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
import ar.com.fdvs.dj.domain.constants.Transparency;
import ar.com.fdvs.dj.domain.constants.VerticalAlign;
import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;

public class DynamicJasper {

    public static DynamicReport myReport() throws ColumnBuilderException, JRException, ClassNotFoundException{

        // build report
        Style headerStyle = getHeaderStyle();
        Style detailStyle = new Style();
        detailStyle.setBorder(Border.THIN());

        // build first report
        FastReportBuilder firstReport = getFirstReport(headerStyle, detailStyle);
        DynamicReport firstDynaRep = firstReport.build();

        System.out.println("Returned Dynamic Reports");
        return firstDynaRep;
    }

    private static Style getHeaderStyle() {
        Style headerStyle = new Style();
        headerStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
        headerStyle.setBorderBottom(Border.PEN_2_POINT());
        headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
        headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
        headerStyle.setBackgroundColor(Color.LIGHT_GRAY);
        headerStyle.setTextColor(Color.BLUE);
        headerStyle.setTransparency(Transparency.OPAQUE);
        return headerStyle;
    }

    private static AbstractColumn getColumn(String property, Class type, String title, int width, Style headerStyle, Style detailStyle) throws ColumnBuilderException {
        AbstractColumn columnState = ColumnBuilder.getInstance()
                .setColumnProperty(property, type.getName()).setTitle(title)
                .setWidth(Integer.valueOf(width)).setStyle(detailStyle)
                .setHeaderStyle(headerStyle).build();
        return columnState;
    }

    private static FastReportBuilder getFirstReport(Style headerStyle, Style detailStyle) throws ColumnBuilderException, ClassNotFoundException {

        FastReportBuilder firstReport = new FastReportBuilder();
        AbstractColumn columnState = getColumn("state", String.class, "State", 30, headerStyle, detailStyle);
        AbstractColumn columnBranch = getColumn("branch", String.class, "Branch", 30, headerStyle, detailStyle);
        AbstractColumn columnProductLine = getColumn("productLine", String.class, "Product Line", 50, headerStyle, detailStyle);
        AbstractColumn columnItem = getColumn("item", String.class, "Item", 50, headerStyle, detailStyle);
        AbstractColumn columnaItemCode = getColumn("itemCode", Long.class, "Item Code", 22, headerStyle, detailStyle);
        AbstractColumn columnQuantity = getColumn("quantity", Long.class, "Quantity", 22, headerStyle, detailStyle);
        Style amountStyle = new Style();
        amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
        AbstractColumn columnAmount = ColumnBuilder.getInstance()
                .setColumnProperty("amount", Float.class.getName())
                .setTitle("Amount").setWidth(Integer.valueOf(30))
                .setStyle(amountStyle).setPattern("$ 0.00")
                .setStyle(detailStyle).setHeaderStyle(headerStyle).build();

        AbstractColumn remarks = getColumn("remarks", String.class, "Remarks", 100, headerStyle, detailStyle);
        firstReport.addColumn(columnState).addColumn(columnBranch)
                .addColumn(columnProductLine).addColumn(columnItem)
                .addColumn(columnaItemCode).addColumn(columnQuantity)
                .addColumn(columnAmount).addColumn(remarks);

        firstReport.addFirstPageImageBanner("E:\\DynamicJasperReports\\fdvsolutions_dynamicjasper_project.png",Integer.valueOf(560), Integer.valueOf(51),ImageBanner.ALIGN_LEFT);
        firstReport.setTitle("November 2006 sales report");
        firstReport.setSubtitle("This report was generateed at");
        firstReport.setUseFullPageWidth(true); // make colums to fill the page width

        return firstReport;
    }

    private static FastReportBuilder getSecondReport(Style headerStyle, Style detailStyle) throws ColumnBuilderException {

        FastReportBuilder secondReport = new FastReportBuilder();

        AbstractColumn columnState = getColumn("state", String.class, "State", 30, headerStyle, detailStyle);
        AbstractColumn columnBranch = getColumn("branch", String.class, "Branch", 30, headerStyle, detailStyle);
        AbstractColumn columnProductLine = getColumn("productLine", String.class, "Product Line", 50, headerStyle, detailStyle);
        AbstractColumn columnItem = getColumn("item", String.class, "Item", 50, headerStyle, detailStyle);
        AbstractColumn columnaItemCode = getColumn("itemCode", Long.class, "Item Code", 22, headerStyle, detailStyle);
        AbstractColumn columnQuantity = getColumn("quantity", Long.class, "Quantity", 22, headerStyle, detailStyle);
        Style amountStyle = new Style();
        amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
        AbstractColumn columnAmount = ColumnBuilder.getInstance()
                .setColumnProperty("amount", Float.class.getName())
                .setTitle("Amount").setWidth(Integer.valueOf(30))
                .setStyle(amountStyle).setPattern("$ 0.00")
                .setStyle(detailStyle).setHeaderStyle(headerStyle).build();

        AbstractColumn remarks = getColumn("remarks", String.class, "Remarks", 100, headerStyle, detailStyle);
        secondReport.addColumn(columnState);
        secondReport.addColumn(columnBranch);
        secondReport.addColumn(columnProductLine);
        secondReport.addColumn(columnItem);
        secondReport.addColumn(columnaItemCode);
        secondReport.addColumn(columnQuantity);
        secondReport.addColumn(columnAmount);
        secondReport.addColumn(remarks);

        secondReport.addFirstPageImageBanner("E:\\DynamicJasperReports\\fdvsolutions_dynamicjasper_project.png", Integer.valueOf(560), Integer.valueOf(51), ImageBanner.ALIGN_LEFT);
        secondReport.setTitle("December 2006 sales report");
        secondReport.setSubtitle("This report was generateed at");
        secondReport.setUseFullPageWidth(true); // make colums to fill the page width

        return secondReport;
    }

}

1 个答案:

答案 0 :(得分:0)

ActionContext类具有方法签名

public Object get(String key)

所以这是异常的原因,您应该修改ar.com.fdvs.dj.struts2.DJStruts2Result以及可能使用Object类型参数的其他类或者选择正确的版本。您的maven依赖项也应该与Struts 2框架的具体版本相对应。请参阅我对Conflicts in xwork and xwork-core的回答。