简体   繁体   中英

Spring Boot: class in package not being loaded

I'm having trouble with a Spring Boot app that is not loading a config class with 2 beans in it. The weird thing is that another config class in the same package gets loaded.

Both config classes have @Configuration in them. The one that doesn't load also has a @ComponentScan(basePackages = {"com.example.package.in.jar"}) in it.

The base packages value refers to a package in a loaded jar file.

I'm using Gradle 3.4.1 , Spring Boot 1.5.3 . When I turn on Spring debugging, it shows the other config class being found and loaded, but it just skips over the other one. No exceptions are thrown - no errors at all.

It would be one thing if the code didn't run, but at least load the class or throw an error, but the log file that was created showed no errors.

Use @EntityScan("com.yourpackage*") will check all the packages starts with "com.yourpackage"

Refer https://github.com/Roshanmutha/JPARepo_44149690/blob/master/src/main/java/com/rcmutha/usl/controller/Application.java

So it turns out that the problem was that it the file wasn't even being seen, period. After attempting the suggestions, I found another option to try: @ImportAutoConfiguration. I used this annotation in the main Spring Boot app file and specified the files in my config package. This is when the compiler said that it couldn't resolve the file I was having problems with.

I cut out the contents, deleted the file and re-created it with a slightly different name, pasted back the contents and update the file list for the annotation. It worked!

The file showed up in the file tree in IntelliJ, but it wasn't being seen by the compiler, so it wasn't being configured. Within the annotation it had to look for it explicitly, and then the error was produced.

Thank you to those that posted suggestions.

Les

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM