问题遇到的现象和发生背景
背景:
在学习 尚硅谷尚筹网java项目实战开发教程(含SSM框架,微服务架构,封捷主讲) 视频。
问题相关代码,请勿粘贴截图
TestHandler
package com.atguigu.crowd.mvc.handler;
import com.atguigu.crowd.entity.Auth;
import com.atguigu.crowd.service.api.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
public class TestHandler {
@Autowired
private AuthService authService;
@RequestMapping("/test/ssm.html")
public String testSsm(ModelMap modelMap) {
System.out.println("-------->1TestHandler.testSsm");
List<Auth> authList = authService.getAll();
modelMap.addAttribute("authList", authList);
System.out.println("-------->2TestHandler.testSsm");
return "target";
}
}
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<a href="test/ssm.html ">测试ssm整合环境</a>
</body>
</html>
spring-web-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!--配置自动扫描:扫描handler-->
<context:component-scan base-package="com.atguigu.crowd.mvc"/>
<!--配置SpringMVC的注解驱动-->
<mvc:annotation-driven></mvc:annotation-driven>
<!--配置视图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<!--这个Filter要在所有Filter前面-->
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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-web-mvc.xml,classpath:spring-persist-*.xml</param-value>
</init-param>
<!--Servlet默认生命周期中,创建对象是第一次接受到请求时-->
<!--DispatcherServlet创建对象后有大量的框架初始化工作,不适合在第一次请求时来做-->
<!--这样设置就是为了让DispatcherServlet在web应用启动时创建对象、初始化-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<!--1.url-pattern 表示拦截所有请求-->
<!--<url-pattern>/</url-pattern>-->
<!--2.配置请求扩展名
优点:
1.css js png等等静态资源完全不经过Springmvc,不需要特殊处理
2.实现伪静态效果。表面上看起来访问一个html文件这样的静态资源,但实际上是经过java代码运算过的 作用:给黑客入侵增加难度 利于SEO优化(让搜索引擎更容易找到我们项目)
缺点:
不符合RESTFul风格。-->
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-persist-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
运行结果及报错内容
后端:
E:\tool\servers\Tomcat\apache-tomcat-9.0.37\bin\catalina.bat run
[2022-01-02 06:21:58,371] Artifact atcrowdfunding02-admin-webui:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\ASUS\AppData\Local\JetBrains\IntelliJIdea2020.2\tomcat\Unnamed_FundingOnline_study_4"
Using CATALINA_HOME: "E:\tool\servers\Tomcat\apache-tomcat-9.0.37"
Using CATALINA_TMPDIR: "E:\tool\servers\Tomcat\apache-tomcat-9.0.37\temp"
Using JRE_HOME: "E:\Java\java-2020-03\jdk1.8.0_251\jre"
Using CLASSPATH: "E:\tool\servers\Tomcat\apache-tomcat-9.0.37\bin\bootstrap.jar;E:\tool\servers\Tomcat\apache-tomcat-9.0.37\bin\tomcat-juli.jar"
02-Jan-2022 18:21:59.877 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/9.0.37
02-Jan-2022 18:21:59.879 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器构建: Jun 30 2020 20:09:49 UTC
02-Jan-2022 18:21:59.880 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 服务器版本号(: 9.0.37.0
02-Jan-2022 18:21:59.880 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 操作系统名称: Windows 10
02-Jan-2022 18:21:59.880 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 10.0
02-Jan-2022 18:21:59.880 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 架构: amd64
02-Jan-2022 18:21:59.880 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: E:\Java\java-2020-03\jdk1.8.0_251\jre
02-Jan-2022 18:21:59.880 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java虚拟机版本: 1.8.0_251-b08
02-Jan-2022 18:21:59.880 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation
02-Jan-2022 18:21:59.881 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\ASUS\AppData\Local\JetBrains\IntelliJIdea2020.2\tomcat\Unnamed_FundingOnline_study_4
02-Jan-2022 18:21:59.881 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: E:\tool\servers\Tomcat\apache-tomcat-9.0.37
02-Jan-2022 18:21:59.882 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Djava.util.logging.config.file=C:\Users\ASUS\AppData\Local\JetBrains\IntelliJIdea2020.2\tomcat\Unnamed_FundingOnline_study_4\conf\logging.properties
02-Jan-2022 18:21:59.882 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
02-Jan-2022 18:21:59.882 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dcom.sun.management.jmxremote=
02-Jan-2022 18:21:59.882 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dcom.sun.management.jmxremote.port=1099
02-Jan-2022 18:21:59.882 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dcom.sun.management.jmxremote.ssl=false
02-Jan-2022 18:21:59.882 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dcom.sun.management.jmxremote.password.file=C:\Users\ASUS\AppData\Local\JetBrains\IntelliJIdea2020.2\tomcat\Unnamed_FundingOnline_study_4\jmxremote.password
02-Jan-2022 18:21:59.882 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dcom.sun.management.jmxremote.access.file=C:\Users\ASUS\AppData\Local\JetBrains\IntelliJIdea2020.2\tomcat\Unnamed_FundingOnline_study_4\jmxremote.access
02-Jan-2022 18:21:59.883 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Djava.rmi.server.hostname=127.0.0.1
02-Jan-2022 18:21:59.883 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Djdk.tls.ephemeralDHKeySize=2048
02-Jan-2022 18:21:59.883 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Djava.protocol.handler.pkgs=org.apache.catalina.webresources
02-Jan-2022 18:21:59.883 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dignore.endorsed.dirs=
02-Jan-2022 18:21:59.883 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dcatalina.base=C:\Users\ASUS\AppData\Local\JetBrains\IntelliJIdea2020.2\tomcat\Unnamed_FundingOnline_study_4
02-Jan-2022 18:21:59.883 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Dcatalina.home=E:\tool\servers\Tomcat\apache-tomcat-9.0.37
02-Jan-2022 18:21:59.883 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 命令行参数:-Djava.io.tmpdir=E:\tool\servers\Tomcat\apache-tomcat-9.0.37\temp
02-Jan-2022 18:21:59.884 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent 在java.library.path:[E:\Java\java-2020-03\jdk1.8.0_251\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;E:\Java\jdk1.8.0_251\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;E:\Python_2020\python;E:\Python_2020\python\Scripts;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\WINDOWS\system32;C:\Program Files\MySQL\MySQL Server 8.0\bin;E:\tools\Scripts;D:\LINGO64_18\;E:\tool\servers\Tomcat\apache-tomcat-9.0.37\bin;E:\tool\servers\Tomcat\apache-tomcat-9.0.37\lib;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;E:\Program Files (x86)\IncrediBuild;E:\Python_2020\python\Scripts\;E:\Python_2020\python\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\ASUS\AppData\Local\Microsoft\WindowsApps;C:\Users\ASUS\AppData\Local\GitHubDesktop\bin;.]上找不到基于APR的Apache Tomcat本机库,该库允许在生产环境中获得最佳性能
02-Jan-2022 18:22:00.179 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["http-nio-7080"]
02-Jan-2022 18:22:00.210 信息 [main] org.apache.catalina.startup.Catalina.load 服务器在[550]毫秒内初始化
02-Jan-2022 18:22:00.237 信息 [main] org.apache.catalina.core.StandardService.startInternal 正在启动服务[Catalina]
02-Jan-2022 18:22:00.237 信息 [main] org.apache.catalina.core.StandardEngine.startInternal 正在启动 Servlet 引擎:[Apache Tomcat/9.0.37]
02-Jan-2022 18:22:00.249 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-7080"]
02-Jan-2022 18:22:00.260 信息 [main] org.apache.catalina.startup.Catalina.start [49]毫秒后服务器启动
Connected to server
[2022-01-02 06:22:00,451] Artifact atcrowdfunding02-admin-webui:war exploded: Artifact is being deployed, please wait...
02-Jan-2022 18:22:03.082 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
18:22:03,159 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
18:22:03,160 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
18:22:03,160 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/E:/tool/JetBrains/IdeaProjects/atcrowdfunding01-admin-parent/atcrowdfunding02-admin-webui/target/atcrowdfunding02-admin-webui/WEB-INF/classes/logback.xml]
18:22:03,253 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
18:22:03,259 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
18:22:03,268 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
18:22:03,319 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
18:22:03,319 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
18:22:03,321 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.atguigu.crowd.mapper] to DEBUG
18:22:03,321 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
18:22:03,323 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@4c1cceac - Registering current configuration as safe fallback point
18:22:03,127 |-INFO in ch.qos.logback.classic.servlet.LogbackServletContainerInitializer@5aedb03 - Adding an instance of class ch.qos.logback.classic.servlet.LogbackServletContextListener to the current web-app
[18:22:03.349] [INFO ] [RMI TCP Connection(3)-127.0.0.1] [org.springframework.web.context.ContextLoader]
[Root WebApplicationContext: initialization started]
[18:22:03.484] [INFO ] [RMI TCP Connection(3)-127.0.0.1] [org.springframework.web.context.support.XmlWebApplicationContext]
[Refreshing Root WebApplicationContext: startup date [Sun Jan 02 18:22:03 CST 2022]; root of context hierarchy]
[18:22:03.578] [INFO ] [RMI TCP Connection(3)-127.0.0.1] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
[Loading XML bean definitions from file [E:\tool\JetBrains\IdeaProjects\atcrowdfunding01-admin-parent\atcrowdfunding02-admin-webui\target\atcrowdfunding02-admin-webui\WEB-INF\classes\spring-persist-mybatis.xml]]
[18:22:03.715] [INFO ] [RMI TCP Connection(3)-127.0.0.1] [org.springframework.beans.factory.xml.XmlBeanDefinitionReader]
[Loading XML bean definitions from file [E:\tool\JetBrains\IdeaProjects\atcrowdfunding01-admin-parent\atcrowdfunding02-admin-webui\target\atcrowdfunding02-admin-webui\WEB-INF\classes\spring-persist-tx.xml]]
[18:22:05.050] [INFO ] [RMI TCP Connection(3)-127.0.0.1] [org.springframework.web.context.ContextLoader]
[Root WebApplicationContext: initialization completed in 1695 ms]
02-Jan-2022 18:22:05.074 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 一个或多个筛选器启动失败。完整的详细信息将在相应的容器日志文件中找到
02-Jan-2022 18:22:05.075 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 由于之前的错误,Context[/atcrowdfunding02_admin_webui_war_exploded]启动失败
18:22:05,079 |-INFO in ch.qos.logback.classic.servlet.LogbackServletContextListener@42b0af1e - About to stop ch.qos.logback.classic.LoggerContext [default]
[2022-01-02 06:22:05,106] Artifact atcrowdfunding02-admin-webui:war exploded: Error during artifact deployment. See server log for details.
02-Jan-2022 18:22:10.251 信息 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [E:\tool\servers\Tomcat\apache-tomcat-9.0.37\webapps\manager]
02-Jan-2022 18:22:11.009 信息 [Catalina-utility-1] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
02-Jan-2022 18:22:11.037 信息 [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[E:\tool\servers\Tomcat\apache-tomcat-9.0.37\webapps\manager]的部署已在[785]毫秒内完成
前端:
HTTP状态 404 - 未找到
类型 状态报告
描述 源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示。
Apache Tomcat/9.0.37
我的解答思路和尝试过的方法
1、添加mvc:default-servlet-handler注解,无效。
2、使用welcome-file-list注解指定欢迎页面(index.jsp),无效。
我想要达到的结果
望遇到过相同问题的朋友分享下经验。谢谢~