Java – JasperReportsPdfView cannot be parsed in my spring boot.

JasperReportsPdfView cannot be parsed in my spring boot…. here is a solution to the problem.

JasperReportsPdfView cannot be parsed in my spring boot.

In my Spring Boot, I want to generate a list in PDF format. According to the tutorial and blog, I did everything as described. But in my Controller class, when I declare JasperReportsPdfView view = new JasperReportsPdfView(); , I received a red alert. I didn’t get any suggestions from intellij idea to import classes.
My Controller class is

@Controller
public class PdfController {

@Autowired
    private StudentRepository studentRepository;

@Autowired
    private ApplicationContext applicationContext;

@Autowired
    StudentService studentService;

@GetMapping("/getreport")
    public ModelAndView getReport()
    {
        JasperReportsPdfView view = new JasperReportsPdfView();
        view.setUrl("classpath:/reports/report.jrxml");
        view.setApplicationContext(applicationContext);

Map<String, Object> studentMap = new HashMap<>();
        studentMap.put("datalist", studentService.generateReports());
        return new ModelAndView(view, studentMap);
    }
}

And my pom .xml is

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<groupId>com.avijit</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

<name>test</name>
    <description>Demo project for Spring Boot</description>

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

<dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itextpdf</artifactId>
            <version>5.0.6</version>
        </dependency>

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

<dependency>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
            <version>4.2.2</version>
        </dependency>

<dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.4.0</version>
        </dependency>

<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
    </dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Please anyone help me with this.

Solution

It seems that JasperReports support was removed in Spring 5. See this answer:

https://stackoverflow.com/questions/47271098/spring-5-reporting

Related Problems and Solutions