qwer63782 2022-03-16 16:42 采纳率: 40%
浏览 877

smm框架整合出错,运行报No mapping for GET /book

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图

web.xml

         
<?xml version="1.0" encoding="UTF8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:application-*.xml</param-value>
    </context-param>
    <!--容器加载的监听器-->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <!--Spring MVC 前端控制器-->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <!--初始化参数-->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <!--项目启动时候,初始化前端控制器-->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

spring-mvc.xml

  
<?xml version="1.0" encoding="UTF8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans.xsd
               http://www.springframework.org/schema/mvc
               http://www.springframework.org/schema/mvc/spring-mvc.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 配置要扫描的包 -->
    <context:component-scan base-package="com.dx.controller"/>
    <!-- 配置注解驱动 -->
    <mvc:annotation-driven/>

</beans>


BookController.java

@Controller
public class BookController {
    @Autowired
    private BookService bookService;

    @RequestMapping("/book")
    public ModelAndView findBookById(Integer id){
        System.out.println("aa");
        Book book =bookService.findBookById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("book.jsp");
        modelAndView.addObject("book",book);
        return modelAndView;
    }
}
运行结果及报错内容

输入这个http://localhost:8080/book
控制台

"D:\Program Files (x86)\apache-tomcat-7.0.100\bin\catalina.bat" run
[2022-03-16 04:36:10,469] Artifact ssm002:war: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE:   "C:\Users\28103\AppData\Local\JetBrains\IntelliJIdea2021.2\tomcat\74236b1c-58c3-4184-b97d-86f3abb90ab9"
Using CATALINA_HOME:   "D:\Program Files (x86)\apache-tomcat-7.0.100"
Using CATALINA_TMPDIR: "D:\Program Files (x86)\apache-tomcat-7.0.100\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_301"
Using CLASSPATH:       "D:\Program Files (x86)\apache-tomcat-7.0.100\bin\bootstrap.jar;D:\Program Files (x86)\apache-tomcat-7.0.100\bin\tomcat-juli.jar"
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server.服务器版本:     Apache Tomcat/7.0.100
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: 服务器构建:            Feb 11 2020 08:31:12 UTC
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: 服务器版本号(:7.0.100.0
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 10
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS.版本:               10.0
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: 架构:                  amd64
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java 环境变量:         C:\Program Files\Java\jdk1.8.0_301\jre
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM 版本:              1.8.0_301-b09
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM.供应商:            Oracle Corporation
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         C:\Users\28103\AppData\Local\JetBrains\IntelliJIdea2021.2\tomcat\74236b1c-58c3-4184-b97d-86f3abb90ab9
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         D:\Program Files (x86)\apache-tomcat-7.0.100
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.util.logging.config.file=C:\Users\28103\AppData\Local\JetBrains\IntelliJIdea2021.2\tomcat\74236b1c-58c3-4184-b97d-86f3abb90ab9\conf\logging.properties
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcom.sun.management.jmxremote=
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcom.sun.management.jmxremote.port=1099
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcom.sun.management.jmxremote.ssl=false
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\28103\AppData\Local\JetBrains\IntelliJIdea2021.2\tomcat\74236b1c-58c3-4184-b97d-86f3abb90ab9\jmxremote.password
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\28103\AppData\Local\JetBrains\IntelliJIdea2021.2\tomcat\74236b1c-58c3-4184-b97d-86f3abb90ab9\jmxremote.access
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.rmi.server.hostname=127.0.0.1
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dignore.endorsed.dirs=
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=C:\Users\28103\AppData\Local\JetBrains\IntelliJIdea2021.2\tomcat\74236b1c-58c3-4184-b97d-86f3abb90ab9
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\Program Files (x86)\apache-tomcat-7.0.100
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.io.tmpdir=D:\Program Files (x86)\apache-tomcat-7.0.100\temp
三月 16, 2022 4:36:11 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_301\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;"C:\Program Files\Java\jdk1.8.0_301\bin;C:\Program Files\Java\jdk1.8.0_301\jre\bin;";C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Java\jdk1.8.0_301\bin;C:\Program Files\PuTTY\;C:\Program Files\Git\cmd;D:\Maven\apache-maven-3.8.4\bin\;C:\Program Files\Redis\;C:\Users\28103\AppData\Local\Microsoft\WindowsApps;D:\Program Files (x86)\CLion 2021.2.3\bin;;C:\Users\28103\AppData\Local\GitHubDesktop\bin;.]
三月 16, 2022 4:36:11 下午 org.apache.coyote.AbstractProtocol init
信息: 初始化协议处理器 ["http-bio-8080"]
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 445 ms
三月 16, 2022 4:36:11 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service [Catalina]
三月 16, 2022 4:36:11 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.100
三月 16, 2022 4:36:11 下午 org.apache.coyote.AbstractProtocol start
信息: 开始协议处理句柄["http-bio-8080"]
三月 16, 2022 4:36:11 下午 org.apache.catalina.startup.Catalina start
信息: Server startup in 43 ms
Connected to server
[2022-03-16 04:36:12,149] Artifact ssm002:war: Artifact is being deployed, please wait...
三月 16, 2022 4:36:12 下午 org.apache.catalina.deploy.WebXml setVersion
警告: Unknown version string [4.0]. Default version will be used.
三月 16, 2022 4:36:12 下午 org.apache.catalina.deploy.WebXml setVersion
警告: Unknown version string [4.0]. Default version will be used.
三月 16, 2022 4:36:14 下午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
三月 16, 2022 4:36:14 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext: initialization started
三月 16, 2022 4:36:14 下午 org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl warn
警告: No MyBatis mapper was found in '[com.dx.dao]' package. Please check your configuration.
三月 16, 2022 4:36:15 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
信息: Root WebApplicationContext initialized in 668 ms
三月 16, 2022 4:36:15 下午 org.springframework.web.servlet.FrameworkServlet initServletBean
信息: Initializing Servlet 'DispatcherServlet'
三月 16, 2022 4:36:15 下午 org.springframework.web.servlet.FrameworkServlet initServletBean
信息: Completed initialization in 382 ms
[2022-03-16 04:36:15,480] Artifact ssm002:war: Artifact is deployed successfully
[2022-03-16 04:36:15,480] Artifact ssm002:war: Deploy took 3,331 milliseconds
三月 16, 2022 4:36:15 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping for GET /
三月 16, 2022 4:36:15 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping for GET /
三月 16, 2022 4:36:15 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping for GET /
三月 16, 2022 4:36:21 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping for GET /aa
三月 16, 2022 4:36:21 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: 把web 应用程序部署到目录 [D:\Program Files (x86)\apache-tomcat-7.0.100\webapps\manager]
三月 16, 2022 4:36:21 下午 org.apache.catalina.deploy.WebXml setVersion
警告: Unknown version string [4.0]. Default version will be used.
三月 16, 2022 4:36:22 下午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
三月 16, 2022 4:36:22 下午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory [D:\Program Files (x86)\apache-tomcat-7.0.100\webapps\manager] has finished in [449] ms
三月 16, 2022 4:36:41 下午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping for GET /book

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

2条回答 默认 最新

  • 程猿薇茑 Java领域优质创作者 2022-03-16 20:48
    关注

    换成不返回modelandview试试
    比如返回json格式

    
    @RequestMapping("/book")
    @ResponseBody
        public Book findBookById(Integer id){
            System.out.println("aa");
            Book book =bookService.findBookById(id);
            return book ;
        }
    
    
    评论

报告相同问题?

问题事件

  • 修改了问题 3月16日
  • 修改了问题 3月16日
  • 创建了问题 3月16日

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境