The SSM project can be started normally but the webpage cannot be accessed. After opening the webpage, an error 404
console output is reported :
2020-11-20 11:10:45.638 INFO 2780 --- [nio-8181-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-11-20 11:10:45.638 INFO 2780 --- [nio-8181-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-11-20 11:10:45.639 INFO 2780 --- [nio-8181-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
After reading some articles on the Internet, I think there should be a problem with the mapper layer. I wrote these two annotations in the main program.
@MapperScan(“com...dao”)
@ComponentScan(“com...entity”)
And also written in the mapper file
@Repository("***mapper")
@Mapper
I just started to learn, I haven't understood the principles inside, it seems that there is a scanning conflict... or something
solution
- Deleted annotations program entry function
@MapperScan("com.**.**.dao") @ComponentScan("com.**.**.entity")
,
the program entry function at only write the@SpringBootApplication
- Also delete the annotations of the mapper file and
@Repository("***mapper")
only keep it@Mapper
- In application.properties file written into
#对应mapper的.xml的位置
mybatis.mapper-locations=classpath:com.**.**.dao/*.xml
#对应实体类的位置
mybatis.type-aliases-package=com.**.**.entity
OK, mine is solved here, I hope it helps you.
: It seems to be very simple, I tossed for two days to solve it.
: Sure enough, you still have to learn the principles clearly!