{"id":469007,"date":"2024-06-06T08:00:00","date_gmt":"2024-06-06T07:00:00","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=qodana&#038;p=469007"},"modified":"2025-08-06T16:01:41","modified_gmt":"2025-08-06T15:01:41","slug":"static-code-analysis-for-spring-run-analysis-fix-critical-errors-hit-the-beach","status":"publish","type":"qodana","link":"https:\/\/blog.jetbrains.com\/fr\/qodana\/2024\/06\/static-code-analysis-for-spring-run-analysis-fix-critical-errors-hit-the-beach","title":{"rendered":"Static Code Analysis for Spring: Run Analysis, Fix Critical Errors, Hit the Beach"},"content":{"rendered":"\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#why-is-it-so-tricky-to-manage-code-quality-in-spring\">Why is it so tricky to manage code quality in Spring?<\/a><\/li><li><a href=\"#spring-qodana-and-intelli-j-idea-how-do-the-three-work-together\">Spring, Qodana, and IntelliJ IDEA: How do the three work together?<\/a><\/li><li><a href=\"#static-code-analysis-for-spring-inspection-groups\">Static code analysis for Spring: inspection groups<\/a><ul><li><a href=\"#spring-autowiring-inspections\">Spring autowiring inspections<\/a><\/li><li><a href=\"#application-configuration-inspections\">Application configuration inspections<\/a><\/li><li><a href=\"#qodana-inspections-and-static-code-analysis-for-spring-data\">Qodana inspections and static code analysis for Spring Data\u00a0<\/a><\/li><li><a href=\"#inspections-for-spring-mvc\">Inspections for Spring MVC<\/a><\/li><\/ul><\/li><li><a href=\"#the-powerful-combination-of-spring-qodana-and-intelli-j-idea\">The powerful combination of Spring, Qodana and IntelliJ IDEA<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p>Why is <a href=\"https:\/\/www.jetbrains.com\/pages\/static-code-analysis-guide\/\" target=\"_blank\" rel=\"noopener\">static code analysis<\/a> for Spring so important? 72% of our JVM users use Spring in their applications, especially in industries like manufacturing and finance. Why? Spring makes programming with Java and <a href=\"https:\/\/www.jetbrains.com\/opensource\/kotlin\/\" target=\"_blank\" rel=\"noopener\">Kotlin<\/a> quicker, easier, and safer for everybody \u2013 but it also comes with unique challenges.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-is-it-so-tricky-to-manage-code-quality-in-spring\">Why is it so tricky to manage code quality in Spring?<\/h2>\n\n\n\n<p>Spring has a rich API interface with annotations and configuration files \u2013 a broad system with many specifics. It\u2019s a framework that works like glue for your app, determining how you structure, build, and run code, freeing you up to think about which logic to apply.&nbsp;<\/p>\n\n\n\n<p>In a Spring Framework project, you can change one file, and everything will still look correct. However, this small change can easily affect your app&#8217;s configuration and lead to errors in other files. It\u2019s possible that you won\u2019t see these errors until you open those other files, which is too late.&nbsp;<\/p>\n\n\n\n<p>To confidently change files in such a project, you need safeguards to help you navigate code quality in such a complex framework. That\u2019s why we originally built the Spring plugin for IntelliJ IDEA to include a wide range of Spring-specific inspections for everyday use.&nbsp; Now, we\u2019ve added Spring-specific inspections to Qodana.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"spring-qodana-and-intelli-j-idea-how-do-the-three-work-together\">Spring, Qodana, and IntelliJ IDEA: How do the three work together?<\/h2>\n\n\n\n<p>The out-of-the-box experience of<a href=\"https:\/\/www.jetbrains.com\/idea\/\" target=\"_blank\" rel=\"noopener\"> IntelliJ IDEA<\/a> gives you everything you need for typical Java and Kotlin development, including Spring. The plugin contributes various checks for Spring Framework and comes bundled with the Qodana JVM linter. <\/p>\n\n\n\n<p>You can find the full list of inspections for Spring Framework in IntelliJ IDEA under <em>Settings | Editor | Inspections<\/em> by searching for \u201cSpring\u201d to filter out irrelevant inspections.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"2474\" height=\"1432\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/1-inspections-spring-core.png\" alt=\"Qodana for Spring BOot code analysis. - and new Spring Framework inspections\n\" class=\"wp-image-469008\"\/><\/figure>\n\n\n\n<p>The same checks run in the IDE when you write code and even include server-side analysis. This means that if you missed some issue in the IDE, it will be detected by the <a href=\"https:\/\/www.jetbrains.com\/qodana\/\" target=\"_blank\" rel=\"noopener\">Qodana<\/a> linter in the CI pipeline. <\/p>\n\n\n\n<p>The Qodana report will reveal the issues that snuck into the project, and everyone on the team will know. Qodana makes code reviews a team sport ahead of runtime, improving overall code quality and bringing enhanced collaboration to your team\u2019s workflow.<\/p>\n\n\n\n<p align=\"center\"><a class=\"jb-download-button\" title=\"Explore all Qodana Features\" href=\"https:\/\/jetbrains.com\/qodana\/features\" target=\"_blank\" rel=\"noopener noreferrer\" data-mce-href=\"https:\/\/jetbrains.com\/qodana\/features\" data-mce-selected=\"inline-boundary\" data-mce-><i class=\"download-icon\"><\/i>Explore all Qodana Features<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"3038\" height=\"1872\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/2-qodana-report-spring-inspections.png\" alt=\"Qodana code reviews, Spring code reviews Inspections in Spring Framework\nIncludes Spring MVC inspections, Spring Boot inspections for better Spring code quality.\" class=\"wp-image-469019\"\/><figcaption class=\"wp-element-caption\">Qodana provides greater team visibility into your project. <\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"static-code-analysis-for-spring-inspection-groups\"><strong>Static code analysis for Spring: inspection groups<\/strong><\/h2>\n\n\n\n<p>Spring inspections can be grouped by use case into checks for issues related to autowiring, configuration files, the data access layer, the web layer, and many more. Let\u2019s take a closer look at some of these groups.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"spring-autowiring-inspections\">Spring autowiring inspections<\/h3>\n\n\n\n<p>As Spring\u2019s programming model relies on annotations, the various components are typically scattered across the project and often reside in different files and packages. It\u2019s not immediately obvious whether the required dependencies exist, whether there are no conflicts, or whether the references to lifecycle methods are correct. These problems fall into the category of autowiring issues, and this is the most typical group of issues that developers face when working with the Spring Framework.<\/p>\n\n\n\n<p>You can spot many autowiring issues in Spring\u2019s context in the editor, highlighted as you type. These include minor recommendations, such as avoiding field injection, or bigger issues, such as a mistyped package name in the ComponentScan annotation.<\/p>\n\n\n\n<p>Let\u2019s look at an example of a situation in which changing one component in a Spring application may cause the failure of another component.<br><br>In Spring applications, it\u2019s possible to describe a dependency between components using the <code>@DependsOn<\/code> annotation, where a dependency name is specified as a string. The components might reside in different parts of the project, and a change in the dependency could potentially break the lifecycle of a dependent component.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"2560\" height=\"1440\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/3-spring-inspections-generalconfig.png\" alt=\"Spring dependancies Qodana and other important Java Spring inspections and Spring Framework checks.Static code analysis for Spring\" class=\"wp-image-469030\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In the screenshot above, the IDE reports that the dependency referenced in the <code>@DependsOn<\/code> annotation parameter cannot be resolved, even though the <code>GeneralConfig<\/code> class that implements the component is visible in the project tree. <\/p>\n\n\n\n<p>The problem is a typo in the reference name: instead of \u201cgeneralconfig\u201d (all lowercase letters), the value should be \u201cgeneralConfig\u201d (with a capital letter \u201cC\u201d) \u2013 that is the convention used in Spring Framework for referencing components in the context of the application.&nbsp;<\/p>\n\n\n\n<p>Even though the issue is highlighted in the editor, it\u2019s easy to miss this error if the change is made elsewhere without updating the reference value. The compilation process won\u2019t detect this issue and simple unit tests won\u2019t catch it either. <\/p>\n\n\n\n<p>What we need is a minimal set of integration tests and additional static code checks. This is where Qodana comes in handy, as this type of issue is included in the report that JetBrains\u2019 flagship code quality platform generates.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"2450\" height=\"1314\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/4-spring-inspections-generalconfig-qodana-report.png\" alt=\"Spring GeneralConfig Qodana inspections, Debugging in Spring Framework should be included in Spring Framework best practices.\n\" class=\"wp-image-469044\"\/><figcaption class=\"wp-element-caption\">Qodana reports make it easier to run static code analysis for Spring &#8211; find and resolve issues. <\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"application-configuration-inspections\">Application configuration inspections<\/h3>\n\n\n\n<p>Configuration issues are annoying. A little typo in a configuration file can cause an application to misbehave or even crash. <\/p>\n\n\n\n<p>Configuration inspections report unresolved and deprecated configuration keys and invalid values in the configuration files of Spring Boot application properties, which can lead to runtime errors.&nbsp;<\/p>\n\n\n\n<p>For instance, the configuration might include deprecated property names. This may occur when we upgrade the version of Spring Framework in the project but remember to update the configuration accordingly.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"2560\" height=\"1440\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/5-spring-application-properties.png\" alt=\"Spring Application configuration inspections and Spring application inspections for better code quality.\" class=\"wp-image-469056\"\/><\/figure>\n\n\n\n<p>Another type of configuration issue involves the misspelling of property values. For instance, in the screenshot above, the value of the <code>spring.devtools.restart.poll-interval <\/code>property is highlighted in red. This value should be spelled as \u201c5m\u201d instead of \u201c5min\u201d.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"qodana-inspections-and-static-code-analysis-for-spring-data\">Qodana inspections and static code analysis for Spring Data&nbsp;<\/h3>\n\n\n\n<p>Spring Data relies on its method naming convention to generate database queries. Although this approach is very convenient, it\u2019s easy to miss the convention unless you\u2019re paying very close attention.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1786\" height=\"772\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/6-intellij-spring-data-warning.png\" alt=\"Code quality Inspections for Spring Data\u00a0Qodana, improving code with Spring inspections.\" class=\"wp-image-469068\"\/><\/figure>\n\n\n\n<p>In the example above, the convention for the <code>findByType<\/code> method signature requires the <code>PetType<\/code> class as a parameter, but <code>Integer<\/code><em> <\/em>was used as a parameter instead. To fix this, we can either extract a JPQL query into a <a href=\"https:\/\/docs.spring.io\/spring-data\/jpa\/reference\/jpa\/query-methods.html#jpa.query-methods.at-query\" target=\"_blank\" rel=\"noopener\">Query annotation<\/a> for the method or simply change the parameter type.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"2015\" height=\"1067\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/7-intellij-extract-jpql-query.png\" alt=\"findByType method Spring inspections, JetBrains Qodana \" class=\"wp-image-469079\"\/><\/figure>\n\n\n\n<p>There are more checks that verify that the code using Spring Data follows the applicable conventions. For instance, you\u2019ll be notified if the method name doesn\u2019t match the property name of the entity.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1782\" height=\"712\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/8-intellij-extract-owner-name.png\" alt=\"\" class=\"wp-image-469090\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"2852\" height=\"1844\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/9-qodana-spring-data-report.png\" alt=\"\" class=\"wp-image-469101\"\/><figcaption class=\"wp-element-caption\">Use Qodana to view issues in your code directly in your IDE. <\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"inspections-for-spring-mvc\">Inspections for Spring MVC<\/h3>\n\n\n\n<p>Data access isn\u2019t the only place where Spring Framework relies on naming conventions. Another example where you need to be aware of the conventions is the implementation of the web layer. <\/p>\n\n\n\n<p>When working with Spring MVC, typically we refer to external resources or path variables by name. It\u2019s easy to make a typo and then the external resource won\u2019t be resolved.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1742\" height=\"628\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/10-spring-mvc-view.png\" alt=\"Inspections in Spring MVC, Qodana code quality\" class=\"wp-image-469112\"\/><\/figure>\n\n\n\n<p>The inspections for Spring MVC can also detect the unresolved references in the <code>PathVariable <\/code>annotation and missing resources for template engineers like Thymeleaf.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"2770\" height=\"1802\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2024\/04\/11-spring-mvc-qodana-report.png\" alt=\"PathVariable annotation and missing resources Spring, JetBrains Qodana\" class=\"wp-image-469123\"\/><figcaption class=\"wp-element-caption\">Easily navigate issue reports in the Qodana interface. <\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-powerful-combination-of-spring-qodana-and-intelli-j-idea\">The powerful combination of Spring, Qodana and IntelliJ IDEA<\/h2>\n\n\n\n<p>Spring Framework is a popular yet complex framework where a lot of its functionality is based on naming conventions, or relies on component name references that are not validated at compile time. <\/p>\n\n\n\n<p>IntelliJ IDEA validates Spring Framework conventions as you type in the editor, while Qodana builds on top of IntelliJ IDEA\u2019s static analysis engine to provide visibility into the project for the whole team. <\/p>\n\n\n\n<p>As a direct result, you can use Qodana to increase productivity, improve code quality, and provide learning opportunities to developers at various stages of seniority. <\/p>\n\n\n\n<p><strong>Got questions on code quality for the Qodana team?<\/strong><\/p>\n\n\n\n<p>Reach out to qodana-support@jetbrains.com \u2013 <a href=\"https:\/\/twitter.com\/Qodana\" target=\"_blank\" rel=\"noopener\">or follow us on X (formerly Twitter)<\/a> and <a href=\"https:\/\/www.linkedin.com\/showcase\/qodana\/?viewAsMember=true\" target=\"_blank\" rel=\"noopener\">LinkedIn<\/a> for code quality updates. You can also <a href=\"https:\/\/www.jetbrains.com\/help\/qodana\/getting-started.html\" target=\"_blank\" rel=\"noopener\">view the documentation<\/a> to get started.<\/p>\n\n\n\n<p align=\"center\"><a class=\"jb-download-button\" title=\"Get a Qodana demo\" href=\"https:\/\/www.jetbrains.com\/qodana\/request-a-demo\/\" target=\"_blank\" rel=\"noopener noreferrer\" data-mce-href=\"https:\/\/www.jetbrains.com\/qodana\/request-a-demo\/\" data-mce-selected=\"inline-boundary\" data-mce-><i class=\"download-icon\"><\/i>Get a Qodana demo<\/a><\/p>\n","protected":false},"author":820,"featured_media":480158,"comment_status":"closed","ping_status":"closed","template":"","categories":[8859,8867],"tags":[4068,2547,40,6470,276,8243],"cross-post-tag":[6284],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/qodana\/469007"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/qodana"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/types\/qodana"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/users\/820"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/comments?post=469007"}],"version-history":[{"count":10,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/qodana\/469007\/revisions"}],"predecessor-version":[{"id":590378,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/qodana\/469007\/revisions\/590378"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/media\/480158"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/media?parent=469007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/categories?post=469007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/tags?post=469007"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/fr\/wp-json\/wp\/v2\/cross-post-tag?post=469007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}