【问题标题】:Spring Java based configuration for Crystal ReportsCrystal Reports 基于 Spring Java 的配置
【发布时间】:2017-11-20 06:21:14
【问题描述】:

我刚开始使用水晶报表创建我的应用程序,并在其中使用了一些 java 注释配置。现在我正在尝试与水晶报告集成,我必须将基于 xml 的 web.xml 转换为基于 java 的配置 这是 web.xml 代码

<?xml version="1.0" encoding="UTF-8"?>
  <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/appServlet/servlet-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- crystal report in spring -->
    <context-param>
        <param-name>crystal_image_uri</param-name>
        <param-value>/crystalreportviewers</param-value>
    </context-param>
    <context-param>
        <param-name>crystal_image_use_relative</param-name>
        <param-value>webapp</param-value>
    </context-param>

    <servlet>
        <servlet-name>CrystalReportViewerHandler</servlet-name>
        <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CrystalReportViewerHandler</servlet-name>
        <url-pattern>/CrystalReportViewerHandler</url-pattern>
        <url-pattern>/faces/CrystalReportViewerHandler</url-pattern>
    </servlet-mapping>

</web-app>

我曾尝试将它与 java config 混合使用,但失败了, 提前致谢

【问题讨论】:

  • show pls servlet-context.xml 和“我试图将它与 java config 混合但它失败了”,你得到什么异常?

标签: java xml spring spring-mvc crystal-reports


【解决方案1】:

要将您的基本 web.xml 转换为 java 配置,请通过

创建一个类
  • 实现 WebApplicationInitializer 或
  • 扩展 AbstractAnnotationConfigDispatcherServletInitializer

关于您的水晶报表,您可以使用@Bean Annotation 创建 CrystalReportViewerServlet 类型的 Bean。

更多信息请查看 - web.xml to java configregister secondary servlet in spring

【讨论】:

  • 谢谢,我做了身份证
【解决方案2】:

感谢所有寻求解决方案的人。我做了以下

@Configuration
@ComponentScan(basePackages = { "t.g.app" })
public class ReportsConfig implements WebApplicationInitializer{

@Override
public void onStartup(ServletContext servletContext) throws ServletException{
    servletContext.setInitParameter("crystal_image_uri","/crystalreportviewers");
    servletContext.setInitParameter("crystal_image_use_relative", "webapp");
    ServletRegistration.Dynamic crystalReportViewerHandler = servletContext
              .addServlet("CrystalReportViewerHandler", new CrystalReportViewerServlet());

    crystalReportViewerHandler.setLoadOnStartup(1);
    crystalReportViewerHandler.addMapping("/CrystalReportViewerHandler");
    }
}

还有一些spring security引起的安全问题,所以我在安全配置中添加了一些异常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 1970-01-01
    • 2014-09-25
    • 2012-02-01
    相关资源
    最近更新 更多