Repository navigation
Closed
Labels
for: eclipsesomething that is specific for Eclipsefor: vscodesomething that is specific for VSCodetheme: validationtype: bug
Milestone
Description
Describe the bug
If a @Bean annotation is applied to an @Override method in a class that implements an interface requiring said implemented method to be a public method, the STS4 linter will indicate a false positive.
To Reproduce
- Copy the following code a Spring MVC or Spring Boot project of your choice:
package my.pkg.namespace;
import java.nio.charset.StandardCharsets;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MessageValidatorConfiguration implements WebMvcConfigurer {
@Bean
MessageSource messageSource ( ) {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
return messageSource;
}
// WARNING shows here by the "public" accessor keyword.
@Bean
@Override
public LocalValidatorFactoryBean getValidator ( ) {
LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
bean.setValidationMessageSource(messageSource());
return bean;
}
}- As indicated in the comment above, the
@Beancan be applied to thegetValidator(), which is a method to be implemented for the interfaceWebMvcConfigurer. However, the side effect is the@Beanwould hint that thepublicaccess modifier must not need to be present, which conflicts with the@Overridetag.
The class WebMvcConfigurer comes from this source code file from the Spring Web MVC project:
Is this a false positive? Please let me know. Thank you in advance.
We do use this wacky set up where we can autowire an overridden LocalValidatorFactoryBean class. There is no indication that we're doing this the right or wrong way, but it's being used for a couple of years in production for us.
Metadata
Metadata
Assignees
Labels
for: eclipsesomething that is specific for Eclipsefor: vscodesomething that is specific for VSCodetheme: validationtype: bug
Activity
BoykoAlex commentedon Jun 9, 2026
Yes, we shouldn't be flagging the overriden methods
goutamadwant commentedon Jun 17, 2026
@martinlippert Opened #1915 with a small fix for this.
This change keeps the existing override check and also checks inherited superclass/interface methods.. so public @bean methods like WebMvcConfigurer#getValidator() are not reported as JAVA_PUBLIC_BEAN_METHOD.
Do not flag overridden bean methods
Do not flag overridden bean methods (#1915)