我无法在任何服务器上运行我的应用程序。我已经正确配置了Tomcat 9.0.27(以及以前的版本,只是为了查看更改是否有影响),并且在应用程序启动时它已成功部署,但是我在本地主机上看到一个404页,说:“原始服务器未找到目标资源的当前表示或不愿意透露其存在。”当我在Jboss服务器上运行wildfly时,我得到一个页面,显示“禁止访问”。
这是Tomcat的输出日志:
[2019-11-07 08:54:33,282] Artifact firstMicroservice:war: Waiting for server connection to start artifact deployment...
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
07-Nov-2019 08:54:33.899 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/8.5.47
07-Nov-2019 08:54:33.900 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Oct 7 2019 13:30:46 UTC
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 8.5.47.0
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 10.14.5
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 13.0.1+9
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /Users/ethan.murphy@ibm.com/Library/Caches/IntelliJIdea2019.2/tomcat/Unnamed_firstMicroservice_2
07-Nov-2019 08:54:33.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /Users/ethan.murphy@ibm.com/Documents/apache-tomcat-8.5.47
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/Users/ethan.murphy@ibm.com/Library/Caches/IntelliJIdea2019.2/tomcat/Unnamed_firstMicroservice_2/conf/logging.properties
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=/Users/ethan.murphy@ibm.com/Library/Caches/IntelliJIdea2019.2/tomcat/Unnamed_firstMicroservice_2/jmxremote.password
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=/Users/ethan.murphy@ibm.com/Library/Caches/IntelliJIdea2019.2/tomcat/Unnamed_firstMicroservice_2/jmxremote.access
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
07-Nov-2019 08:54:33.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
07-Nov-2019 08:54:33.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
07-Nov-2019 08:54:33.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/Users/ethan.murphy@ibm.com/Library/Caches/IntelliJIdea2019.2/tomcat/Unnamed_firstMicroservice_2
07-Nov-2019 08:54:33.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/Users/ethan.murphy@ibm.com/Documents/apache-tomcat-8.5.47
07-Nov-2019 08:54:33.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/Users/ethan.murphy@ibm.com/Documents/apache-tomcat-8.5.47/temp
07-Nov-2019 08:54:33.906 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/ethan.murphy@ibm.com/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
07-Nov-2019 08:54:33.936 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
07-Nov-2019 08:54:33.943 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
07-Nov-2019 08:54:33.953 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
07-Nov-2019 08:54:33.954 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
07-Nov-2019 08:54:33.954 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 307 ms
07-Nov-2019 08:54:33.986 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
07-Nov-2019 08:54:33.986 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.47
07-Nov-2019 08:54:33.995 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
07-Nov-2019 08:54:34.004 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
07-Nov-2019 08:54:34.006 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 51 ms
Connected to server
[2019-11-07 08:54:34,385] Artifact firstMicroservice:war: Artifact is being deployed, please wait...
[2019-11-07 08:54:34,615] Artifact firstMicroservice:war: Artifact is deployed successfully
[2019-11-07 08:54:34,615] Artifact firstMicroservice:war: Deploy took 230 milliseconds
07-Nov-2019 08:54:44.002 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/Users/ethan.murphy@ibm.com/Documents/apache-tomcat-8.5.47/webapps/manager]
07-Nov-2019 08:54:44.040 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/Users/ethan.murphy@ibm.com/Documents/apache-tomcat-8.5.47/webapps/manager] has finished in [37] ms
但是如果我有一个,它将显示index.jsp。
以该程序为例:
helloController.java:
package spring.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class helloController {
@RequestMapping("/hello")
public String redirect(){
return "viewpage";
}
@RequestMapping("/helloagain")
public String display(){
return "final";
}
}
spring-servlet.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: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">
<!-- Provide support for component scanning -->
<context:component-scan base-package="spring.Controller" />
<!--Provide support for conversion, formatting and validation -->
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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>SpringMVC</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
final.jsp,index.jsp,viewpage.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Welcome to spring </h1>
</body>
</html>
//index.jsp
<html>
<body>
<a href = "hello">Click here</a>
</body>
</html>
//viewpage.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<a href = "helloagain">Hello world</a>
</body>
</html>
两个服务器都将显示index.jsp“单击我”页面,但是当单击链接时,Tomcat会转到404页面,而wildfly在屏幕顶部显示URL。对于多个IDE,这是相同的。