2017-06-17 79 views
0

新的泉水晶報表我創建了我的應用程序,我用了一些java註釋配置。現在我想用水晶報表,我必須基於XML的web.xml轉換爲基於Java的配置 這裏被集成在web.xml代碼水晶報表基於Spring Java的配置

<?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的配置組合,但它失敗, 在此先感謝

+0

顯示pls servlet-context.xml和「我試圖將它與java配置混合但失敗」,你會得到什麼異常? – xyz

回答

0

要將基本的web.xml轉換爲Java配置,無論是通過

  • 創建一個類實現WebApplicationInitializer或
  • 延長阿布斯tractAnnotationConfigDispatcherServletInitializer

關於您的水晶報表,您可以使用@Bean Annotation創建CrystalReportViewerServlet類型的Bean。

更多信息,請 - web.xml to java configregister secondary servlet in spring

+0

謝謝,我發了id –

0

感謝所有誰看了解決方案。我做了以下

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

也有一些安全問題引起的彈簧安全,所以我在安全配置中添加了一些例外。