# S2226 should not raise issues for field annotated with @Autowire in Servlet

**URL:** <https://community.sonarsource.com/t/s2226-should-not-raise-issues-for-field-annotated-with-autowire-in-servlet/2627>\
**Category:** Report False-positive / False-negative...\
**Tags:** sonarqube, java\
**Created:** [September 17, 2018, 12:10pm UTC](https://community.sonarsource.com/t/s2226-should-not-raise-issues-for-field-annotated-with-autowire-in-servlet/2627 "2018-09-17T12:10:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![orimarko](https://avatars.discourse-cdn.com/v4/letter/o/7ab992/32.png) [@orimarko](https://community.sonarsource.com/u/orimarko)\
**Post date:** [September 17, 2018, 12:10pm UTC](https://community.sonarsource.com/t/s2226-should-not-raise-issues-for-field-annotated-with-autowire-in-servlet/2627/1 "2018-09-17T12:10:05Z")

</div>

I’m auto-wiring Spring bean in Servlets, SonarQube is warning that “all servlet fields should then be either static and/or final”

But it similar false positive as SONARJAVA-2744 which was Java’s @Inject

Code:

```auto
public class MyServlet extends HttpServlet {
    @Autowire
    private MySpringBean mySpringBean;
}

```

---

<div class="post-metadata">

**Author:** ![saberduck](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/saberduck/32/27_2.png) [@saberduck](https://community.sonarsource.com/u/saberduck)\
**Post date:** [September 18, 2018, 11:34am UTC](https://community.sonarsource.com/t/s2226-should-not-raise-issues-for-field-annotated-with-autowire-in-servlet/2627/2 "2018-09-18T11:34:09Z")

</div>

Indeed the issue should not be raised on such field same way as it is not raised on field annotated with @Inject, @Resource or @EJB.

I created an issue to fix this [https://jira.sonarsource.com/browse/SONARJAVA-2895](https://jira.sonarsource.com/browse/SONARJAVA-2895)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/78532_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [April 8, 2021, 9:36am UTC](https://community.sonarsource.com/t/s2226-should-not-raise-issues-for-field-annotated-with-autowire-in-servlet/2627/3 "2021-04-08T09:36:58Z")

</div>

Closed on April 8, 2021, 9:36am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
