简体   繁体   English

基于Spring Java的Crystal Reports配置

[英]Spring Java based configuration for Crystal Reports

Im new to spring with crystal reports I have created my application where I used some java annotation configuration. 我对Crystal报表不熟悉,我创建了应用程序,在其中使用了一些Java注释配置。 Now I am trying to integrate with crystal reports where I have to convert xml based web.xml to java based config here is the web.xml code 现在,我试图与Crystal报表集成,在这里我必须将基于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>

I have tried to mix it with java config but it fails, Thanks in advance 我尝试将其与java config混合使用,但失败,在此先感谢

To convert your basic web.xml to java configuration, either create a class by 要将基本的web.xml转换为Java配置,请通过创建一个类

  • implement WebApplicationInitializer or 实现WebApplicationInitializer或
  • extend AbstractAnnotationConfigDispatcherServletInitializer 扩展AbstractAnnotationConfigDispatcherServletInitializer

regarding your crystal report you can create the Bean of type CrystalReportViewerServlet using @Bean Annotation. 关于水晶报表,您可以使用@Bean Annotation创建CrystalReportViewerServlet类型的Bean。

for more information please check - web.xml to java config and register secondary servlet in spring 有关更多信息,请检查-web.xml到java配置在Spring中注册辅助servlet。

Thanks for to all who looked for a solution. 感谢所有寻求解决方案的人。 I did the following 我做了以下

@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");
    }
}

There were also some security issues caused by spring security so i added some exceptions in security configuration. 春季安全性还引起了一些安全性问题,因此我在安全性配置中添加了一些例外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM