Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Eclipse项目中获取HTTP 404错误_Eclipse_Http_Spring Mvc_Tomcat_Tcserver - Fatal编程技术网

在Eclipse项目中获取HTTP 404错误

在Eclipse项目中获取HTTP 404错误,eclipse,http,spring-mvc,tomcat,tcserver,Eclipse,Http,Spring Mvc,Tomcat,Tcserver,我正在尝试学习如何在服务器上运行SpringMVC项目(这方面还是很新的),我遇到了一个HTTP404错误。。我正在Windows7机器上使用EclipseLuna4.4.1、Java7、Spring4.1.4和PivotalTcserver3.0.2。在进一步讨论之前,让我说一下,在使用Tomcat 7创建一个简单的实践项目时,我得到了相同的404错误,因此我认为问题出在我的服务器配置中的某个地方(在tc server和Tomcat中)。下面是一个屏幕截图,显示了我的项目目录、我尝试运行的服务

我正在尝试学习如何在服务器上运行SpringMVC项目(这方面还是很新的),我遇到了一个HTTP404错误。。我正在Windows7机器上使用EclipseLuna4.4.1、Java7、Spring4.1.4和PivotalTcserver3.0.2。在进一步讨论之前,让我说一下,在使用Tomcat 7创建一个简单的实践项目时,我得到了相同的404错误,因此我认为问题出在我的服务器配置中的某个地方(在tc server和Tomcat中)。下面是一个屏幕截图,显示了我的项目目录、我尝试运行的服务器以及错误页面:

程序代码看起来不错。当我运行HomeControllerTest(我基本上是从Craig Walls的第四版Spring in Action中获得的)时,它编译并通过了。我还需要在哪里查找此问题的疑难解答? ` 包com.kwalker.practicewellness

import org.junit.Test;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import com.kwalker.practicewellness.web.HomeController;

public class HomeControllerTest {

@Test
public void testHomePage() throws Exception {
    HomeController controller = new HomeController();
    MockMvc mockMvc = standaloneSetup(controller).build();

    mockMvc.perform(get("/")).andExpect(view().name("home"));

}

}
` 以下是HomeController类:

package com.kwalker.practicewellness.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {

@RequestMapping(value="/", method=RequestMethod.GET)
public String home() {
    return "home";
}
}
以下是WellnessWebAppInitializer:

package com.kwalker.practicewellness.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WellnessWebAppInitializer extends
    AbstractAnnotationConfigDispatcherServletInitializer {

@Override
protected Class<?>[] getRootConfigClasses() {
    return new Class<?>[] { RootConfig.class };
}

@Override
protected Class<?>[] getServletConfigClasses() {
    return new Class<?>[] { WebConfig.class };
}

@Override
protected String[] getServletMappings() {
    return new String[] { "/" };
}

}
以下是网络配置:

package com.kwalker.practicewellness.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan("practicewellness.web")
public class WebConfig extends WebMvcConfigurerAdapter {

@Bean
public ViewResolver viewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/views/");
    resolver.setSuffix(".jsp");
    resolver.setExposeContextBeansAsAttributes(true);
    return resolver;
}

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
}

}
以下是home.jsp页面:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet"
        type="text/css"
        href="<c:url value="/resources/style.css"/>">
</head>
<body>
<h1>
Welcome to Vital Potential!  
</h1>

<P>  The time on the server is ${serverTime}. </P>
</body>
</html>
以下是控制台上的输出:(只有一个警告,与我正在观看的训练视频上的警告相同,对他们来说运行良好):


在您的所有配置中,您似乎都不正确地使用了
@ComponentScan
-基本包名称缺少
com.kwalker.
部分-我猜组件扫描没有拾取您的主控制器

尝试将配置中的基本包更新为完整包名


此外,如果您在信息日志模式下启动服务器,您应该会获得所有已注册控制器/路径的详细信息,这可能会对它有更多的了解。

根据上面发布的代码,您正在尝试编写单元测试用例。发布实际控制器和spring配置文件。同时检查控制台,有可能在启动时出现错误,导致无法加载整个web应用程序。我在控制台中没有看到任何显示问题的内容。控制台输出顶部附近的一个警告也出现在我正在观看的培训视频的输出中,当他们运行示例时,它对他们很有效。还有别的地方我可以看吗?就是这样!非常感谢你!我记得当我用这种方式写它的时候,我对此感到困惑,但《行动中的春天》一书(第四版,第138页)中的例子就是这样列出了基本包,所以我就用了它。它现在运行正常。
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Welcome</title>
<link rel="stylesheet"
        type="text/css"
        href="<c:url value="/resources/style.css"/>">
</head>
<body>
<h1>
Welcome to Vital Potential!  
</h1>

<P>  The time on the server is ${serverTime}. </P>
</body>
</html>
[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder    org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Practice Wellness 1.0.0-BUILD-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ practicewellness ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ practicewellness ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.954 s
[INFO] Finished at: 2015-01-04T10:37:59-07:00
[INFO] Final Memory: 8M/115M
[INFO] ------------------------------------------------------------------------
Jan 04, 2015 10:42:37 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to  'org.eclipse.jst.jee.server:Practice Wellness' did not find a matching property.
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.57
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Nov 3 2014 08:39:16 UTC
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.57.0
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 7
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            6.1
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JAVA_HOME:             C:\Program Files\Java\jdk1.7.0_71\jre
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.7.0_71-b14
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:            C:\Users\kyle\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Apache-Tomcat\apache-tomcat-7.0.57
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -    Dcatalina.base=C:\Users\kyle\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Apache-Tomcat\apache-tomcat-7.0.57
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: - Dwtp.deploy=C:\Users\kyle\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Apache-Tomcat\apache-tomcat-7.0.57\endorsed
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Jan 04, 2015 10:42:37 AM 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: C:\Program   Files\Java\jdk1.7.0_71\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Orac le\Java\javapath;C:\Program Files (x86)\HP SimplePass 2011\x64;C:\Program Files (x86)\HP SimplePass  2011\;;C:\Program Files\Broadcom\Broadcom 802.11\Driver;;C:\Program Files\Common Files\Microsoft   Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows  Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common  Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio  Shared\12.0\DLLShared\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\WIDCOMM\Bluetooth  Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program  Files\Broadcom\WHL\;C:\Program Files\Broadcom\WHL\syswow64;C:\Program  Files\Broadcom\WHL\SysWow64\;C:\Program Files\Broadcom\WHL\SysWow64\syswow64;C:\Program Files  (x86)\Intel\Services\IPT\;C:\Program Files\Java\jdk1.8.0_25\bin;C:\Program Files\Gradle\Gradle- 2.0\gradle-2.2.1\bin;.
Jan 04, 2015 10:42:37 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 04, 2015 10:42:37 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jan 04, 2015 10:42:37 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 911 ms
Jan 04, 2015 10:42:38 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 04, 2015 10:42:38 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.57
Jan 04, 2015 10:42:40 AM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath:  [com.kwalker.practicewellness.config.WellnessWebAppInitializer@4eda480b]
Jan 04, 2015 10:42:40 AM 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.AnnotationConfigWebApplicationContext - Refreshing  Root WebApplicationContext: startup date [Sun Jan 04 10:42:40 MST 2015]; root of context hierarchy
INFO : org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Registering annotated classes: [class com.kwalker.practicewellness.config.RootConfig]
 INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 524 ms
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization started
Jan 04, 2015 10:42:41 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
INFO : org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Refreshing  WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun Jan 04 10:42:41 MST  2015]; parent: Root WebApplicationContext
INFO : org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Registering annotated classes: [class com.kwalker.practicewellness.config.WebConfig]
INFO : org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor - JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/**]  onto handler of type [class  org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler]
INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter -  Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date   [Sun Jan 04 10:42:41 MST 2015]; parent: Root WebApplicationContext
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcher': initialization completed in 1029 ms
Jan 04, 2015 10:42:42 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jan 04, 2015 10:42:42 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 04, 2015 10:42:42 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4348 ms