0

我是 SpringSource 的新手,我从模板创建了一个 Spring MVC 项目,除了在服务器home.jsp文件上运行之外我什么也没做但是我得到了404 error

我不知道该怎么做,因为我的控制台没有错误。我能做些什么?请帮我。

这是我在控制台中得到的内容 在此先感谢。

(我无法附上图片,因为我没有足够的声望点。)

6월 17, 2013 1:47:04 오전 com.springsource.tcserver.security.PropertyDecoder <init>
INFO: tc Runtime property decoder using memory-based key
6월 17, 2013 1:47:04 오전 com.springsource.tcserver.security.PropertyDecoder <init>
INFO: tcServer Runtime property decoder has been initialized in 200 ms
6월 17, 2013 1:47:04 오전 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
6월 17, 2013 1:47:04 오전 com.springsource.tcserver.serviceability.rmi.JmxSocketListener init
INFO: Started up JMX registry on 127.0.0.1:6969 in 86 ms
6월 17, 2013 1:47:04 오전 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 638 ms
6월 17, 2013 1:47:04 오전 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
6월 17, 2013 1:47:04 오전 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: VMware vFabric tc Runtime 2.8.2.RELEASE/7.0.35.B.RELEASE
6월 17, 2013 1:47:04 오전 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\springsource\vfabric-tc-server-developer-2.8.2.RELEASE\base-instance\conf\Catalina\localhost\test.xml
6월 17, 2013 1:47:04 오전 org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:test' did not find a matching property.
6월 17, 2013 1:47:05 오전 org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
6월 17, 2013 1:47:05 오전 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Mon Jun 17 01:47:05 KST 2013]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/root-context.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2db55393: defining beans []; root of factory hierarchy
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 201 ms
6월 17, 2013 1:47:05 오전 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Mon Jun 17 01:47:05 KST 2013]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]
INFO : org.springframework.context.annotation.ClassPathBeanDefinitionScanner - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@73ca0d49: defining beans [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.view.InternalResourceViewResolver#0,homeController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@2db55393
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.example.test.HomeController.home(java.util.Locale,org.springframework.ui.Model)
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 540 ms
6월 17, 2013 1:47:06 오전 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\springsource\vfabric-tc-server-developer-2.8.2.RELEASE\base-instance\webapps\manager
6월 17, 2013 1:47:06 오전 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\springsource\vfabric-tc-server-developer-2.8.2.RELEASE\base-instance\webapps\ROOT
6월 17, 2013 1:47:06 오전 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
6월 17, 2013 1:47:06 오전 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1684 ms

这是我的 home.jsp 文件。

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
    <title>Home</title>
</head>
<body>
<h1>
    Hello world!  
</h1>

<P>  The time on the server is ${serverTime}. </P>
</body>
</html>

和我的 web.xml 文件..

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
4

2 回答 2

2

你想访问http://localhost:8080/your-context-root/WEB-INF/views/home.jsp吗?

如果是这样,请尝试访问: http://localhost:8080/your-context-root/

您将看到“Hello world!”。

于 2013-06-16T18:59:08.913 回答
0

在 Eclipse 中创建默认 Spring MVC 项目时,我遇到了同样的问题。通常,当您看到 404 时,您收集的应用程序的根上下文路径存在问题。

在 Eclipse 中,您可以在 PROJECT_NAME/.settings/ org.eclipse.wst.common.component下的文件中找到该集合。

<property name="context-root" value="my_app"/>

因此http://localhost:8080/my_app会起作用。

还要检查/Servers/Tomcat v7.0 Server/ server.xml

<Context docBase="project_name " path="/my_app" reloadable="true" source="org.eclipse.jst.jee.server:eatin"/>
于 2013-11-01T12:23:44.470 回答