spring-boot: In Spring Boot 3.0.3, component scanning does not work when application's path contains one characters that would be URL encoded and it's not being run as an archive

Write any simple configuration class:

@Configuration
public class ProjectConfig {

  @Bean
  public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
    return http.build();
  }

  @Bean
  public String anyBean() {
    return "Test";
  }
}

Any of these beans are not created. If you add a breakpoint in the methods and start with debug you can see that they are not called at all.

However, adding a @Bean method in the Main class works:

@SpringBootApplication
public class Sb303IssueRepApplication {

  public static void main(String[] args) {
    SpringApplication.run(Sb303IssueRepApplication.class, args);
  }

  @Bean
  public String anyBean() {
    return "Test";
  }
}

This issue cannot be reproduced with 3.0.2.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 33 (11 by maintainers)

Most upvoted comments

For anyone watching this issue, we’ve just done an earlier than scheduled 3.0.4 release to specifically address this regression. Please upgrade.

Thanks everyone! You’re such a great team! I love this community!

I can reproduce the problem. Rather than being specific to Windows, it happens when the application’s path contains a space, which is much more common on Windows than it is on other operating systems. The log output for #34380 shows multiple spaces in the path:

G:\Java\IntelliJ Workspace\Learning\Spring Boot By Raghu\Spring Boot Data\SpringBootDataJpaStoredProcedureEx\target\classes

I cannot reproduce the problem, even with a space in the application’s path, when using Spring Boot 3.0.3 and Framework 6.0.4 @dev-himanshu, are you certain that your downgrade to Spring Framework 6.0.4 was effective?

Any luck fixing issue on 3.0.3 ? On 3.0.2 works perfectly

@HerNidza You can downgrade the spring Framework to 6.0.4 and still use spring-boot 3.0.3 until this is fixed. Simply add the property <spring-framework.version>6.0.4</spring-framework.version>

@kamrankamilli As described in the existing comments on this issue, the problem is not specific to Windows. It will affect an application on any OS when there are characters in its path that are encoded when included in a URL. Spaces are probably the most common.

It looks like it’s a URL encoding problem:

14:58:42.632 [main] DEBUG org.springframework.core.io.support.PathMatchingResourcePatternResolver - Failed to complete search in directory [/Users/awilkinson/dev/temp/youtube%20channel/sb303_issue_rep/target/test-classes/com/example/sb303_issue_rep] for files matching pattern [*.class]: java.nio.file.NoSuchFileException: /Users/awilkinson/dev/temp/youtube%20channel/sb303_issue_rep/target/test-classes/com/example/sb303_issue_rep

Note the %20 in the file’s path. This looks like a regression introduced in https://github.com/spring-projects/spring-framework/commit/dbf360997aba5177775c231e473e1b0d8d8bcf06. The problem does not occur when running the application as a packaged jar. That’s another pointer towards the Framework change being the cause as it will only come into play with file: URLs not the jar: URLs that java -jar will yield. We’ll get the Framework team to take a look.

Thanks for the confirmation, @dev-himanshu.