The SSM project can be started normally, but the webpage cannot be accessed, an error 404 is reported, and the console: Initializing Spring DispatcherServlet'dispatcherServlet'.

The SSM project can be started normally but the webpage cannot be accessed. After opening the webpage, an error 404
Insert picture description here
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”)

Insert picture description here

And also written in the mapper file

@Repository("***mapper")
@Mapper

Insert picture description here

I just started to learn, I haven't understood the principles inside, it seems that there is a scanning conflict... or something

solution

  1. Deleted annotations program entry function @MapperScan("com.**.**.dao") @ComponentScan("com.**.**.entity"),
    the program entry function at only write the@SpringBootApplication
  2. Also delete the annotations of the mapper file and @Repository("***mapper")only keep it@Mapper
  3. 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!

Guess you like

Origin blog.csdn.net/weixin_49035356/article/details/109842951