Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #34379

Closed
lspil opened this issue Feb 25, 2023 · 33 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@lspil
Copy link

lspil commented Feb 25, 2023

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 25, 2023
@lspil
Copy link
Author

lspil commented Feb 25, 2023

Here you have a simple project that reproduces the issue: https://github.com/lspil/youtubechannel/tree/master/sb303_issue_rep

@lspil
Copy link
Author

lspil commented Feb 25, 2023

Also, here's a short unlisted video with my issue: https://www.youtube.com/watch?v=5pLtEWy7ByA

@maciejwalkowiak
Copy link
Contributor

@lspil I run the sample on both Java 19 and Java 17 and cannot reproduce this issue.

@dev-himanshu
Copy link

Hi @wilkinsona , As you have suspected it's a Windows-specific problem related to component scanning, Is there any way to fix it at our end?

@wilkinsona
Copy link
Member

wilkinsona commented Feb 25, 2023

Thanks for trying the sample, @maciejwalkowiak. I too cannot reproduce the problem on macOS. My suspicion is that it's a Windows-specific problem as both @lspil and @dev-himanshu, the raiser of #34380, are using Windows. What OS did you try on, @maciejwalkowiak?

@lspil Can you please run your application on the command line using Maven with trace level logging enabled:

mvnw spring-boot:run -Dspring-boot.run.jvmArguments=-Dlogging.level.org.springframework=trace

Please do this with both Spring Boot 3.0.2 and Spring Boot 3.0.3 and share the complete output of both runs. It would also be interesting to know if the problem occurs with Spring Boot 3.0.3 when you downgrade to Spring Framework 6.0.4. You can do so by adding <spring-framework.version>6.0.4</spring-framework.version> to the <properties> in your pom.xml.

@dev-himanshu
Copy link

Hi @wilkinsona,
I have tried but not working by using spring boot 3.0.3 with spring framework 6.0.4

@maciejwalkowiak
Copy link
Contributor

@wilkinsona on MacOS. Will give a try on Windows later this weekend.

@wilkinsona
Copy link
Member

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?

@wilkinsona
Copy link
Member

wilkinsona commented Feb 25, 2023

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 spring-projects/spring-framework@dbf3609. 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.

@wilkinsona wilkinsona changed the title In Spring Boot 3.0.3 methods annotated with @Bean in any configuration class are not considered anymore at startup In Spring Boot 3.0.3, component scanning does not work when application's path contains one or more spaces and it's not being run as an archive Feb 25, 2023
@wilkinsona
Copy link
Member

wilkinsona commented Feb 25, 2023

#30031 is already tracking this on the Framework side. Closing in favor of that issue. We'll pick up a new release of Framework that fixes the problem in due course.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Feb 25, 2023
@wilkinsona wilkinsona added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 25, 2023
@dev-himanshu
Copy link

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?

I am sure that downgrade to spring framework 6.0.4 was not effective in my case.

@rishiraj88
Copy link

Thanks, @dev-himanshu

@wilkinsona
Copy link
Member

@dev-himanshu Was Framework 6.0.4 definitely on the classpath? If it was, you appear to have a different problem. It would be interesting to know if your application works when run from a location with no spaces in its path.

@puck-codes
Copy link

I had exactly the same problem with two Spring Boot 3.0.3 projects on Windows OS, I replaced all the spaces in the path with hyphens C:\..\path-to-folder\..\project and they both work fine now.

Like lspil said, I didn't have this problem on 3.0.2.

@lspil
Copy link
Author

lspil commented Feb 26, 2023

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

@dev-himanshu
Copy link

@dev-himanshu Was Framework 6.0.4 definitely on the classpath? If it was, you appear to have a different problem. It would be interesting to know if your application works when run from a location with no spaces in its path.

In Runner.java

package com.example.runners;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class Runner implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
        log.info("Runner execution started.");
        System.out.println("Runner is running.....");
        log.info("Runner execution completed.");
    }
}

Console Output:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.3)

2023-02-26T11:44:43.945+05:30  INFO 10112 --- [  restartedMain] c.example.SpringTestRunnerApplication    : Starting SpringTestRunnerApplication using Java 18.0.2.1 with PID 10112 (H:\SpringTestRunner\target\classes started by himan in H:\SpringTestRunner)
2023-02-26T11:44:43.951+05:30  INFO 10112 --- [  restartedMain] c.example.SpringTestRunnerApplication    : No active profile set, falling back to 1 default profile: "default"
2023-02-26T11:44:44.003+05:30  INFO 10112 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-02-26T11:44:44.523+05:30  INFO 10112 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2023-02-26T11:44:44.540+05:30  INFO 10112 --- [  restartedMain] c.example.SpringTestRunnerApplication    : Started SpringTestRunnerApplication in 1.326 seconds (process running for 3.046)
2023-02-26T11:44:44.542+05:30  INFO 10112 --- [  restartedMain] com.example.runners.Runner               : Runner execution started.
Runner is running.....
2023-02-26T11:44:44.542+05:30  INFO 10112 --- [  restartedMain] com.example.runners.Runner               : Runner execution completed.

Process finished with exit code 0

Hello @wilkinsona
Yes, you are right. I tried with the no spaces path and its working
So, There is URL encoder issue only.

@wilkinsona
Copy link
Member

Thanks for the confirmation, @dev-himanshu.

@dev-himanshu
Copy link

you're welcome @wilkinsona

@123Haynes
Copy link

123Haynes commented Feb 27, 2023

This also happens if the path contains other chars like ## not only with spaces.
I ran into this because my application is named frontend##3.0.0.war so the tomcat manager recognizes the 3.0.0 as the version number.

@wilkinsona wilkinsona changed the title In Spring Boot 3.0.3, component scanning does not work when application's path contains one or more spaces and it's not being run as an archive 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 Feb 27, 2023
@kamrankamilli
Copy link

kamrankamilli commented Feb 28, 2023

I have issue with spring boot 3.0.3 using Ubuntu, I'm not sure if it is specific to Windows. Previously I was using Spring Boot 3.0.2 and had no problems. Looks like spring is not scanning for components.

//Working
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

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

	@GetMapping("/hello")
	public String hello() {
		return "hello";
	}

}



//Not working no mapping 404

package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("/hello/hello")
    public String hello() {
        return "hello";
    }
}

@wilkinsona
Copy link
Member

@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.

@kamrankamilli
Copy link

@wilkinsona Yeah I had space in my project folder name, now it is working thanks

@jruedas1

This comment was marked as off-topic.

@jruedas1

This comment was marked as off-topic.

@jruedas1

This comment was marked as off-topic.

@jruedas1

This comment was marked as off-topic.

@jruedas1

This comment was marked as off-topic.

@wilkinsona

This comment was marked as resolved.

@SuperUserDo-Nikola
Copy link

Any luck fixing issue on 3.0.3 ?
On 3.0.2 works perfectly

@123Haynes
Copy link

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>

@SuperUserDo-Nikola
Copy link

@123Haynes Awesome!

Thanks a lot!

@philwebb
Copy link
Member

philwebb commented Mar 3, 2023

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

@dev-himanshu
Copy link

dev-himanshu commented Mar 4, 2023

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

Hi @philwebb, thanks for the update in that issue. I have tried with latest release of 3.0.4 and now working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

13 participants