注意Spring Boot 项目的代码结构!
由于喜欢捯饬项目结果,喜欢一开始就为他们分层规整,却忘掉了Spring Boot 对项目结果的要求,即@SpringBootApplication类存放的位置,对其他注解扫描的影响。
在学习Spring-Boot-Security中,按照官网教程完成代码,但运行结果一直报错,找了很多论坛都没有解决。想起有一次也是因为带有注解@SpringBootApplicationde类放置的位置出错使得,其他注解不会被扫描到。 一开始我的目录是与这样的:
Here is a typical layout:
com
+- example
+- myproject
+- Application.java
|
+- domain
| +- Customer.java
| +- CustomerRepository.java
|
+- service
| +- CustomerService.java
|
+- web
+- CustomerController.java
We generally recommend that you locate your main application class in a root package above other classes. The @EnableAutoConfiguration annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items.