Search code examples
javaspringeclipsespring-tool-suitespring-tools-4

Eclipse with Spring Tools 4 gives a warning on public @Bean methods


I have just upgraded Eclipse to version 2023-09 and installed Spring Tools 4 from the marketplace. Now, in projects using Spring Boot 2.7.18, I get a lot of warnings because I have the public modifier on @Bean methods. Is it a bad practice? This post says that the method visibility does not affect the bean's visibility and, in facts, I have not found anything about access modifiers of @Bean methods in Spring docs and this manual page has an example with a public @Bean method. So why should I change it? Can this note be disabled?

Update: added some screen-shots. Now I see that in the Properties dialog it has "Info" severity but in the "Markers" view it is under a warning icon due to the presence of other messages. It has also a quick fix.

Screen-shot1

Screen-shot1

Screen-shot2


Solution

  • Found it: under "Window/Preferences/Spring/Validation/Boot 2.x Best Practices & Optimizations" there is a "Public '@Bean' method" option that you can set to "Ignore". The tooltip says:

    Public modifier on '@Bean' method. They no longer have to be public visibility to be usable by Spring.