我有一个奇怪的流程,当我尝试启动spring-mvc项目时,所有内容都在构建并使用localhost:8080
地址正确启动,但它仅显示Apache Tomcat主页并且每个请求都显示示例localhost:8080/login
显示HTTP Status 404 – Not Found
description:The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
奇怪的是,当我尝试在另一台计算机(Ubuntu)中运行相同项目时,它运行正常,登录页面正确显示并且每次请求工作良好。奇怪的是,这台意外的流程首次出现在这台机器上。
tomcat version is 8.5.24
这是我的dispatcher-servlet.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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
这里是applicationContext.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"
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">
<context:component-scan base-package="com.awesome"/>
</beans>
这是我的配置类
@Configuration
@ComponentScan("com.awesome")
@EnableWebMvc
open class AppConfig : WebMvcConfigurerAdapter() {
@Bean
open fun viewResolver(): InternalResourceViewResolver {
val internalResourceViewResolver = InternalResourceViewResolver()
internalResourceViewResolver.setSuffix(".jsp")
internalResourceViewResolver.setPrefix("/")
return internalResourceViewResolver
}
override fun configureDefaultServletHandling(configurer: DefaultServletHandlerConfigurer?) {
configurer?.enable()
}
}
这是控制器
@Controller
class HomeController {
@RequestMapping("/", method = [(RequestMethod.GET)])
fun displayLoginPage(): String {
return "login"
}
@RequestMapping("/login", method = [(RequestMethod.POST)])
fun login(@RequestParam user_name:String, @RequestParam password: String, modelMap: ModelMap): String {
return "main"
}
}
这是启动日志
"C:\Program Files\apache-tomcat-8.5.24\bin\catalina.bat" run
[2018-01-22 03:18:25,411] Artifact Wall5:war: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5"
Using CATALINA_HOME: "C:\Program Files\apache-tomcat-8.5.24"
Using CATALINA_TMPDIR: "C:\Program Files\apache-tomcat-8.5.24\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.8.0_144"
Using CLASSPATH: "C:\Program Files\apache-tomcat-8.5.24\bin\bootstrap.jar;C:\Program Files\apache-tomcat-8.5.24\bin\tomcat-juli.jar"
22-Jan-2018 15:18:26.852 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.24
22-Jan-2018 15:18:26.854 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Nov 27 2017 13:05:30 UTC
22-Jan-2018 15:18:26.854 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.24.0
22-Jan-2018 15:18:26.854 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.0
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_144\jre
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_144-b01
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5
22-Jan-2018 15:18:26.855 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: C:\Program Files\apache-tomcat-8.5.24
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5\conf\logging.properties
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
22-Jan-2018 15:18:26.857 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\dev--\.IntelliJIdea2017.3\system\tomcat\Unnamed_Wall5
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\apache-tomcat-8.5.24
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\apache-tomcat-8.5.24\temp
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
22-Jan-2018 15:18:26.858 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
22-Jan-2018 15:18:27.854 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2m 2 Nov 2017]
22-Jan-2018 15:18:28.547 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
22-Jan-2018 15:18:28.563 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Jan-2018 15:18:28.569 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
22-Jan-2018 15:18:28.571 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
22-Jan-2018 15:18:28.571 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2114 ms
22-Jan-2018 15:18:28.596 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
22-Jan-2018 15:18:28.596 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.24
22-Jan-2018 15:18:28.625 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
22-Jan-2018 15:18:28.638 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
22-Jan-2018 15:18:28.641 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 69 ms
答案 0 :(得分:1)
我已经修复了问题,我刚刚看到了我的工件,并且我用war
更改了exploded
工件,现在一切正常。
答案 1 :(得分:0)
在c turbo编译器中首先编译零错误的代码,按f9可见,然后按ctrl + f9输出,然后按alt + f5,结果将在提示窗口中显示。