2022-04-14

Multiple JasperPrint into a pdf with output as file and byte[]

 Multiple JasperPrint into a pdf with output as file and byte[]

JasperExportManager.exportReportToPdf vs JRPdfExporter.exportReport()








Found: https://community.jaspersoft.com/questions/526021/how-merge-multiple-pdf-jasper-reports-one







Multiple JasperPrint into a file
setCreatingBatchModeBookmarks

public void pdf() throws JRException { long start = System.currentTimeMillis(); List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>(); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report1.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report2.jrprint")); jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report3.jrprint")); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("build/reports/BatchExportReport.pdf")); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setCreatingBatchModeBookmarks(true); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); }



JRPdfExporter to byte array

Found: https://www.tabnine.com/code/java/methods/net.sf.jasperreports.engine.export.JRPdfExporter/setParameter

public byte[] exportToPdf(JasperPrint jasperPrint) throws JRException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JRPdfExporter exporter = new JRPdfExporter(jasperReportsContext); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(baos)); exporter.exportReport(); return baos.toByteArray(); }




more Java JRPdfExporter.exportReport方法代碼示例
Found: https://vimsky.com/zh-tw/examples/detail/java-method-net.sf.jasperreports.engine.export.JRPdfExporter.exportReport.html


示例1: export
示例2: savePDFReportToOutputStream
示例3: concatPDFReport
示例4: concatPDFReportEncrypted


Billson: file
示例5: pdf























2022-04-13

Resolved: No qualifying bean of type 'org.springframework.boot.web.client.RestTemplateBuilder'

 
JUnit
TestCase
Spring Boot


Add annotation of 
@AutoConfigureWebClient
to your test case.

org.springframework.boot.test.autoconfigure.web.client.AutoConfigureWebClient



Together with
@ContextConfiguration(classes = {LocalConfig.class})

org.springframework.test.context.ContextConfiguration


public class LocalConfig {

/**
*/
public LocalConfig() {
}
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
   // Do any additional configuration here
   return builder.build();
}

}


to resolve this.

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.web.client.RestTemplateBuilder' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}






org.springframework.beans.factory.BeanFactory.getBean( ) with args

 


org.springframework.beans.factory.BeanFactory.getBean( ) with args


Source URL: https://www.programcreek.com/java-api-examples/?class=org.springframework.beans.factory.BeanFactory&method=getBean

public static void main(String[] args) {
    // 配置 XML 配置文件
    // 启动 Spring 应用上下文
    BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-instantiation-context.xml");
    User user = beanFactory.getBean("user-by-static-method", User.class);
    User userByInstanceMethod = beanFactory.getBean("user-by-instance-method", User.class);
    User userByFactoryBean = beanFactory.getBean("user-by-factory-bean", User.class);
    System.out.println(user);
    System.out.println(userByInstanceMethod);
    System.out.println(userByFactoryBean);

    System.out.println(user == userByInstanceMethod);
    System.out.println(user == userByFactoryBean);

}


Details at:







2022-04-12

@RunWith vs @SpringBootTest

 

https://stackoverflow.com/questions/58901288/springrunner-vs-springboottest







@RunWith(SpringRunner.class) : You need this annotation to just enable spring boot features like @Autowire@MockBean etc.. during junit testing

is used to provide a bridge between Spring Boot test features and JUnit. Whenever we are using any Spring Boot testing features in our JUnit tests, this annotation will be required.

@SpringBootTest : This annotation is used to load complete application context for end to end integration testing

The @SpringBootTest annotation can be used when we need to bootstrap the entire container. The annotation works by creating the ApplicationContext that will be utilized in our tests.

Here is the article with clear examples on both scenarios Baeldung














Resolved: Caused by: java.lang.IllegalStateException: Unable to retrieve @EnableAutoConfiguration base packages

 




Referring to URL below:
https://github.com/spring-projects/spring-boot/issues/10465#issuecomment-336397898
 
Added @AutoConfigurationPackage to avoid error: Caused by: java.lang.IllegalStateException: Unable to retrieve @EnableAutoConfiguration base packages

into the class u made as:
org.springframework.context.annotation.Configuration




Relevant reads:
  1. https://blog.csdn.net/wuqingsssss/article/details/113115809
  2. https://its401.com/article/wuqingsssss/113115809




Google Referrals