404未找到:原始服务器未找到目标资源的当前表示,或不愿意透露存在的资源
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了404未找到:原始服务器未找到目标资源的当前表示,或不愿意透露存在的资源相关的知识,希望对你有一定的参考价值。
这是我得到的错误,我使用Gradle作为构建工具,我尝试了所有解决方案在互联网上
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name: Apache Tomcat/9.0.27
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Oct 7 2019 09:57:22 UTC
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 9.0.27.0
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Linux
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 5.0.0-32-generic
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Private Build
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:
/home/sudarshan/work/.metadata/.plugins/org.eclipse.wst.server.core/tmp1
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /home/sudarshan/Downloads/apache-tomcat-9.0.27
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -
Dcatalina.base=/home/sudarshan/work/.metadata/.plugins/org.eclipse.wst.server.core/tmp1
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/home/sudarshan/Downloads/apache-tomcat-9.0.27
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -
Dwtp.deploy=/home/sudarshan/work/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/
wtpwebapps
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/home/sudarshan/Downloads/apache-tomcat-
9.0.27/endorsed
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Oct 24, 2019 3:01:35 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in
production environments was not found on the java.library.path:
[/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-
gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
Oct 24, 2019 3:01:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-2016"]
Oct 24, 2019 3:01:35 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Oct 24, 2019 3:01:35 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [549] milliseconds
Oct 24, 2019 3:01:35 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Oct 24, 2019 3:01:35 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.27]
Oct 24, 2019 3:01:36 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Oct 24, 2019 3:01:37 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
Oct 24, 2019 3:01:37 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class
[org.springframework.web.context.ContextLoaderListener]
java.lang.NoClassDefFoundError:
Lorg/springframework/beans/factory/access/BeanFactoryReference;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:110)
at org.apache.catalina.core.DefaultInstanceManager.populateAnnotationsCache
(DefaultInstanceManager.java:402)
at
org.apache.catalina.core.DefaultInstanceManager.newInstance
(DefaultInstanceManager.java:173)
at org.apache.catalina.core.DefaultInstanceManager.newInstance
(DefaultInstanceManager.java:151)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4607)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5146)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
org.apache.tomcat.util.threads.InlineExecutorService.execute
(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.apache.tomcat.util.threads.InlineExecutorService.execute
(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:633)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:344)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:475)
Caused by: java.lang.ClassNotFoundException:
org.springframework.beans.factory.access.BeanFactoryReference
at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
... 37 more
Oct 24, 2019 3:01:37 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Oct 24, 2019 3:01:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate
container log file
Oct 24, 2019 3:01:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/HibernateTemplate] startup failed due to previous errors
Oct 24, 2019 3:01:37 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Oct 24, 2019 3:01:37 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
Oct 24, 2019 3:01:37 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Oct 24, 2019 3:01:37 PM org.springframework.web.context.ContextLoader
initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Oct 24, 2019 3:01:37 PM org.springframework.context.support.AbstractApplicationContext
prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Thu Oct 24 15:01:37 IST 2019];
root of context hierarchy
Oct 24, 2019 3:01:38 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-core-
config.xml]
Oct 24, 2019 3:01:38 PM org.springframework.web.context.ContextLoader
initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 188 ms
Oct 24, 2019 3:01:38 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'springDispatcherServlet'
Oct 24, 2019 3:01:38 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'springDispatcherServlet': initialization started
Oct 24, 2019 3:01:38 PM org.springframework.context.support.AbstractApplicationContext
prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'springDispatcherServlet-servlet':
startup date [Thu Oct 24 15:01:38 IST 2019]; parent: Root WebApplicationContext
Oct 24, 2019 3:01:38 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader
loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-mvc-
config.xml]
Oct 24, 2019 3:01:38 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
registerHandler
INFO: Root mapping to handler 'homeController'
Oct 24, 2019 3:01:38 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'springDispatcherServlet': initialization completed in 425 ms
Oct 24, 2019 3:01:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-2016"]
Oct 24, 2019 3:01:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Oct 24, 2019 3:01:38 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [2,794] milliseconds
这是我的build.gradle,在其中添加了必需的依赖项
plugins
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'war'
id 'org.gretty' version '2.3.1'
repositories
jcenter()
dependencies
// This dependency is exported to consumers, that is to say found on their compile
classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile
classpath.
implementation 'com.google.guava:guava:28.0-jre'
// https://mvnrepository.com/artifact/org.springframework/spring-web
compile group: 'org.springframework', name: 'spring-web', version: '4.3.13.RELEASE'
// https://mvnrepository.com/artifact/org.springframework/spring-webmvc
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.14.RELEASE'
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
// https://mvnrepository.com/artifact/javax.servlet/jstl
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.13'
// https://mvnrepository.com/artifact/org.springframework/spring-jdbc
compile group: 'org.springframework', name: 'spring-jdbc', version: '5.1.5.RELEASE'
// https://mvnrepository.com/artifact/org.springframework/spring-beans
compile group: 'org.springframework', name: 'spring-beans', version: '5.1.5.RELEASE'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
这是我的spring-core-config.xml
<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: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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
</beans>
这是我的spring-mvc-config.xml
<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: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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="HibernateTemplate"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/userdb"></property>
<property name="username" value="root"></property>
<property name="password" value="password"></property>
</bean>
<bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>
<bean id="dao" class="HibernateTemplate.StudentDao">
<property name="template" ref="jt"></property>
</bean>
</beans>
这是我的web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-
app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>web application</display-name>
<!-- The front controller of this Spring Web application, responsible for handling all
application requests -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-core-config.xml</param-value>
</context-param>
</web-app>
这是我的index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="empform">Add Employee</a>
<!-- <a href="viewemp">View Employees</a> -->
</body>
</html>
studform.jsp文件,我在其中创建了要取值的表单。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="empform">Add Employee</a>
<!-- <a href="viewemp">View Employees</a> -->
</body>
</html>
index.jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="empform">Add Employee</a>
<!-- <a href="viewemp">View Employees</a> -->
</body>
</html>
Student.java类
package HibernateTemplate;
public class Student
private int id;
private String name;
private String email;
public int getId()
return id;
public void setId(int id)
this.id = id;
public String getName()
return name;
public void setName(String name)
this.name = name;
public String getEmail()
return email;
public void setEmail(String email)
this.email = email;
StudentController类
package HibernateTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import HibernateTemplate.Student;
import HibernateTemplate.StudentDao;
@Controller
public class StudentController
@Autowired
StudentDao dao;
/*It displays a form to input data, here "command" is a reserved request attribute
which is used to display object data into form */
@RequestMapping("/studform")
public String showform(Model m)
m.addAttribute("command", new Student());
return "studform";
/*It saves object into database. The @ModelAttribute puts request data into model object.
*You need to mention RequestMethod.POST method
because default request is GET*/
@RequestMapping(value="/save",method = RequestMethod.POST)
public String save(@ModelAttribute("std") Student std)
dao.save(std);
return "save"; //will redirect to viewemp request mapping
StudentDao类
package HibernateTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
public class StudentDao
JdbcTemplate template;
public void setTemplate(JdbcTemplate template)
this.template = template;
public int save(Student s)
String sql="insert into student(id,name,email)
values('"+s.getId()+"',"+s.getName()+",'"+s.getEmail()+"')";
return template.update(sql);
我只需要连接数据库,即可继续进行进一步的操作,您可以推荐我的书,在那里我可以使用gradle学习spring MVC,因为没有gradle在互联网上可用的东西。
答案
尝试从<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
的<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
中删除它。我认为这是不必要的。这可能会导致问题。
以上是关于404未找到:原始服务器未找到目标资源的当前表示,或不愿意透露存在的资源的主要内容,如果未能解决你的问题,请参考以下文章
为啥 Wordpress 无法加载资源?它表示服务器响应状态为 404(未找到)