In daily development, public modules are often packaged and released, and then the contents of the public package are called. However, after the company's public modules were recently organized and released. Spring cannot scan the corresponding beans. The following article mainly introduces the solution to the problem that Spring cannot scan the beans in the jar package during automatic scanning. Friends in need can refer to it.
Found the problem
I used eclipse to package a jar package a few days ago. Inside the jar package are the defined Spring beans.
Then put the jar package under lib, and set spring to automatically scan the beans in the jar package. But who knew that the beans could not be scanned at all, and an error was displayed that the beans could not be found. I was puzzled at that time. Why can't it be scanned? After searching, I discovered that when using eclipse to package the jar package, you need to check "Add directory entries" to be correctly scanned by Spring. There is such a saying, haha... I don’t know
You have to check "Add directory entries" to be scanned by spring
Solution
So I searched again and found out what is the difference between checking "Add directory entries" and not checking it? It really does exist. You can view the jar through the command "jar tf selected.jar
" Regarding the contents of the package, the checked jar package will display the directory level information, while the unchecked jar package will not be displayed. It is estimated that the directory level information can be displayed by spring.
"Add directory entries" adds directory level information
The above is the detailed content of Solution to the problem that Spring automatic scanning in JAVA cannot scan beans in jar packages. For more information, please follow other related articles on the PHP Chinese website!