After upgrading spring from 4.3.3 to 5.2.7 I'm facing a problem with @scope("prototype") annotation on a method with @Bean. actually, spring is trying to initialize the bean at startup even though I'm not using it anywhere (i have tried to delete the bean or rename it and restart the app and all works fine but when I add it again I got the same exception )

EXCEPTION

Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyBean' defined in com.test: Unsatisfied dependency expressed through method 'MyBean' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
PS: I'm sure I'm not using the bean anywhere at startup I just need it when the app is already started
CODE

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@SuppressWarnings({ "unchecked" })
public MyBean MyBean(String url,
        String user, String password, String id) {
    return MyBean(url, user, password, id,
            new HashMap<String, String>(),false); 
}
i have already tried to use Optional < String > as parameters and @Nullable and it's not working because i have to test if the parameters are present otherwise i have to return null and that cause another problem in spring

Bean instance of type [class org.springframework.beans.factory.support.NullBean] is not a FactoryBean
in my case i don't have to edit the type of parameters and the returning type of bean or i may cause a regressiin in the existing code