0

I've got a class like this (from Spring Java Config: how do you create a prototype-scoped @Bean with runtime arguments?)

@Configuration
public class ServiceConfig {

    @Bean
    public Function<DataObj, MyClass> myClassFactory() {
        return data-> myClass(data); 
    }

    @Bean
    @Scope(value = "prototype")
    public MyClass myClass(DataObj data) {
        return new MyClass(data);
    }
}

However, IntelliJ (2020.3) complains about DataObj data - Could not autowire. No beans of 'DataObj' type found. DataObj is not a bean. It is a runtime object that passes data to the construction of the bean. Even if I leave this IntelliJ error as an error (as opposed to a warning), it still works. Why is IntelliJ complaining about this? Is there a way to suppress the error (without turning off the inspection)?

Peter Kronenberg
  • 878
  • 10
  • 32
  • 1
    Please try https://www.jetbrains.com/idea/nextversion/. If the issue persists, file a bug at https://youtrack.jetbrains.com/newIssue?project=IDEA with the reproducible test case. You can suppress inspections for lines/methods/classes, see https://www.jetbrains.com/help/idea/suppressing-inspections.html . – CrazyCoder Mar 31 '21 at 19:14
  • Forgot to mention what release I'm using. I'm at 2020.3, which is the most current, other than EAP. I don't want to suppress the warning in all cases. Couldn't find an annotation to suppress just this instance. I also wanted to post here just to make sure I'm not doing something wrong – Peter Kronenberg Mar 31 '21 at 19:44
  • The suggestion was to try the EAP since several related issues were fixed there. It's an RC right now and will be released next week. – CrazyCoder Mar 31 '21 at 19:44
  • You can suppress it for statement [from the context menu](https://resources.jetbrains.com/help/img/idea/2020.3/suppress-inspection.png). – CrazyCoder Mar 31 '21 at 19:45
  • Ok, thanks. Weren't sure if you were just saying to try it, just in case, or you had actual reason to believe it might fix it. – Peter Kronenberg Mar 31 '21 at 19:47
  • As for suppressing, yes, I Know that is frequently an option, but I don't see that choice [here](https://www.dropbox.com/s/y4r505sw8ur3m0u/2021-03-31%2016_03_20-.png?dl=0) – Peter Kronenberg Mar 31 '21 at 20:05
  • You can suppress is for parameter or method. – CrazyCoder Mar 31 '21 at 20:07

0 Answers0