0
votes

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.

2
If you remove the @ComponentScan from the one that doesn't load currently, does that fix it? What are you attempting to load with the @ComponentScan with? (I'm assuming) Beans in a 3rd party lib?Bwvolleyball
Try to change to @ComponentScan(basePackages = {"classpath*:com.example.package.in.jar"}) the * means search in jars from classpath.StanislavL
None of the 3 suggestions has changed anything. What I don't understand is that whether or not the classes in the jar are resolved or not, why won't the debugger even break in the class? The beans in this class are to be autowired into a class in the jar file. I'd still expect that I should be able to 'break' in the code.Les
Getting sillier. Added a new class, DummyClass, as a test. Put in @Configuration on the class and inside @Bean on a method that just returns a new instance of DummyClass. I put a break point on the return and the debugger broke there. But it still won't address the other class!Les

2 Answers

0
votes
0
votes

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