我不知道发生了什么,但我做的一切都很好。
应用程序启动良好
[2m2023-04-22T03:23:17.326+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.alibou.security.SecurityApplication [0;39m [2m:[0;39m Starting SecurityApplication using Java 17.0.6 with PID 55932 (D:\Descargas\spring-boot-3-jwt-security-main\spring-boot-3-jwt-security-main\target\classes started by luis_ in D:\Descargas\spring-boot-3-jwt-security-main\spring-boot-3-jwt-security-main)
[2m2023-04-22T03:23:17.328+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.alibou.security.SecurityApplication [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default"
[2m2023-04-22T03:23:18.034+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http)
[2m2023-04-22T03:23:18.042+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2023-04-22T03:23:18.042+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/10.1.4]
[2m2023-04-22T03:23:18.128+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/] [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2023-04-22T03:23:18.128+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 761 ms
[2m2023-04-22T03:23:18.436+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http) with context path ''
[2m2023-04-22T03:23:18.444+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[ main][0;39m [36mc.alibou.security.SecurityApplication [0;39m [2m:[0;39m Started SecurityApplication in 1.412 seconds (process running for 1.872)
这是主类
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
@ComponentScan("com.alibou.security.user")
public class SecurityApplication {
public static void main(String[] args) {
SpringApplication.run(SecurityApplication.class, args);
}
}
这就是这个项目的结构
这是一个控制器示例
@RestController
public class Controller {
@GetMapping("/hello")
public String helloWorld() {
return "Hello World";
}
}
这是邮政局的输入
什么都不起作用,我发誓几年前我没有这个问题,现在即使是最简单的事情也不起作用了。
有什么提示吗?
2条答案
按热度按时间j2datikz1#
Baeldung很好地解释了这些注解是如何工作的:https://www.baeldung.com/spring-component-scanning。
基本上,(从他们的网站):
我们使用@SpringBootApplication注解,但它是三个注解的组合:
只有配置类的位置有关系,因为默认情况下组件扫描从其包开始。
因为你已经使用了
@SpringBootApplication
,扫描将从那里开始,所以我认为你不需要在这里有@ComponentScan
注解。除非你想达到你在问题上没有提到的其他目的。emeijp432#
使用上面的代码,它将工作。参考此处Spring Component Scanning