Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 434 Vote(s) - 3.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
intellij incorrectly saying no beans of type found for autowired repository

#1
I have created a simple unit test but IntelliJ is incorrectly highlighting it red. marking it as an error


No beans?

![enter image description here][1]


As you can see below it passes the test? So it must be Autowired?

![enter image description here][2]


[1]:

[2]:
Reply

#2
I encountered this issue too, and resolved it by the removing Spring Facet:

- File -> Project Structure
- Select `Facets`
- Remove Spring


Good luck!
Reply

#3
My solution to this issue in my spring boot application was to open the spring application context and adding the class for the missing autowired bean manually!

(access via Project Structure menu or spring tool window... edit "Spring Application Context")

So instead of SpringApplicationContext just containing my ExampleApplication spring configuration it also contains the missing Bean:

SpringApplicationContext:

- ExampleApplication.java
- MissingBeanClass.java

et voilà: The error message disappeared!
Reply

#4
Putting `@Component` or `@configuration` in your bean config file seems to work, ie something like:

@Configuration
public class MyApplicationContext {
@Bean
public DirectoryScanner scanner() {
return new WatchServiceDirectoryScanner("/tmp/myDir");
}
}

@Component
public class MyApplicationContext {
@Bean
public DirectoryScanner scanner() {
return new WatchServiceDirectoryScanner("/tmp/myDir");
}
}

Reply

#5
And one last piece of important information - add the `ComponentScan` so that the app knows about the things it needs to wire. This is not relevant in the case of this question. However if no `@autowiring` is being performed at all then this is likely your solution.

@Configuration
@ComponentScan(basePackages = {
"some_package",
})
public class someService {
Reply

#6
This seems to still be a bug in the latest IntelliJ and has to do with a possible caching issue?

If you add the @Repository annotation as mk321 mentioned above, save, then remove the annotation and save again, this fixes the problem.
Reply

#7
If you don't want to make any change to you code just to make your IDE happy. I have solved it by adding all components to the Spring facet.

1. Create a group with name "Service, Processors and Routers" or any name you like;
2. Remove and recreate "Spring Application Context" use the group you created previously as a parent.

[![enter image description here][1]][1]


[1]:

Reply

#8
What you need to do is add

`@ComponentScan("package/include/your/annotation/component")` in `AppConfiguration.java`.

Since I think your `AppConfiguraion.java`'s package is **deeper** than your annotation component (@Service, @Component...)'s package,

such as `"package/include/your/annotation/component/deeper/config"`.
Reply

#9
I had a similar problem in my application.
When I added annotations incorrect highliting dissapeared.

@ContextConfiguration(classes = {...})
Reply

#10
My version of IntelliJ IDEA Ultimate (2016.3.4 Build 163) seems to support this. The trick is that you need to have enabled the Spring Data plugin.

[![enter image description here][1]][1]


[1]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through