SpringRESTAPI在qa服务器中部署时抛出404

nhaq1z21  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(257)

spring应用程序,它公开了RESTAPI并部署到tomcat中。应用程序在本地运行良好,但当我部署到qa服务器时,RESTAPI抛出404。
我正在尝试的servelt是rest/*我已经在下面的url中Map了它。
下面是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
     http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <display-name>${project.name} (${project.version}.${BUILD_NUMBER}.${SVN_REVISION})</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath*:META-INF/spring/database-context.xml
            classpath*:META-INF/spring/core-service-context.xml
            classpath*:META-INF/spring/security-service-context.xml
            classpath:META-INF/spring/applicationContext.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>service</servlet-name>

        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.kukri</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>service</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>rest</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/rest-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

以及我的rest-servelt.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">

            <context:component-scan
                    base-package="com.companyname.erp.controller" />
            <mvc:annotation-driven />

            <bean id="viewResolver"
                  class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
                <property name="defaultViews">
                    <list>
                        <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>
                    </list>
                </property>
            </bean>

        </beans>

并在tomcat 9版本和端口8081上部署该应用程序。我已检查了tomcat下的工作文件夹,其中包含我尝试访问的应用程序,并验证了该类,以及在尝试访问postman、curl、wget中的url时包含的控制器,如下所示 http://www.qaerpinterface.companyname.com:8081 它回来了 200 OK 但是当我尝试调用RESTAPI时 http://www.qaerpinterface.companyname.com:8081/rest/ 它还我 404 下面是我的server.xml

<?xml version='1.0' encoding='utf-8'?>

    <Server port="${catalina.port.shutdown}" shutdown="SHUTDOWN">
        <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

        <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

        <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
        <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
        <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

        <GlobalNamingResources>

            <Resource name="UserDatabase" auth="Container"
                      type="org.apache.catalina.UserDatabase"
                      description="User database that can be updated and saved"
                      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                      pathname="conf/tomcat-users.xml" />
        </GlobalNamingResources>

        <Service name="Catalina">
            <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
                      maxThreads="300" minSpareThreads="4"/>

            <Connector executor="tomcatThreadPool"
                       port="${catalina.port.http}" protocol="HTTP/1.1"
                       connectionTimeout="20000"
                       redirectPort="${catalina.port.https}"
                       compression="on"
                       compressionMinSize="16384"
                       noCompressionUserAgents="gozilla,traviata"
                       compressableMimeType="text/html,text/xml,text/javascript,image/jpeg,image/gif,image/png,image/svg+xml"/>
            <Connector port="${catalina.port.ajp13}"
                       protocol="org.apache.coyote.ajp.AjpNio2Protocol"
                       executor="tomcatThreadPool"
                       acceptCount="1000"
                       acceptThreadCount="4"
                       processorCache="300"
                       redirectPort="${catalina.port.https}" />
            <Host name="localhost"  appBase="webapps"
                  unpackWARs="true" autoDeploy="true">

                <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                       prefix="localhost_access_log" suffix=".txt"
                       pattern="%h %l %u %t &quot;%r&quot; %s %b" />

            </Host>
            <Host name="www.qakitdesigner.companyname.com" appBase="webapps/k2-web/webapp"
                  unpackWARs="false" autoDeploy="false"
                  xmlValidation="false" xmlNamespaceAware="false">
                <Context docBase="/opt/tomcat/tomcat8_erp/webapps/k2-web/webapp/ROOT" path="/teamshop" reloadable="true" />

            </Host>
            <Host name="www.qaerpinterface.companyname.com" appBase="webapps/k2-erpInterface/webapp"
                  unpackWARs="false" autoDeploy="false"
                  xmlValidation="false" xmlNamespaceAware="false">
                <Alias>www.testerpinterface3.companyname.com</Alias>
                <Context docBase="/opt/tomcat/tomcat8_erp/webapps/k2-erpInterface/webapp/ROOT" path="/erpinterface" reloadable="true" />
            </Host>
        </Service>
    </Server>

在同一个tomcat中部署了两个应用程序两次大战你们都认为这是问题的根源吗?但是它们都有不同的主机名
任何帮助都是有帮助的,可以尝试google中所有可能的事情,比如更改控制器名称、更新xsd版本。我们正在运行的服务器是linux机器上的apache tomcat Web服务器。
请就如何进一步调试、更改什么或在何处查找提供任何建议?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题