【问题标题】:Resource URIs not working in Java RESTful web service on tomcat 8 server资源 URI 在 Tomcat 8 服务器上的 Java RESTful Web 服务中不起作用
【发布时间】:2016-08-22 16:15:40
【问题描述】:

我使用带有 netbeans 的自动生成的实体类创建了一个 RESTful Web 服务。我也用过maven。我将它部署在 Tomcat 8 中作为本地主机。我确实看到了索引页面,但我无法访问任何端点。我最初在 Glassfish 服务器上本地运行它,它运行良好。 我在 netbeans 中尝试了测试资源 uri,但它说,

无法打开资源 URL : localhost:8080//api/activity

这是我来自 apache tomcat 的 server.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>

 --><Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>

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

  <GlobalNamingResources>

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

  <Service name="Catalina">


    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>

    <Engine defaultHost="localhost" name="Catalina">

      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>

      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

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

      <Context antiJARLocking="true" docBase="C:\xxx\yyyy\apache-tomcat-8.0.36\apache-tomcat-8.0.36\wtpwebapps\xxDBWithMaven" path="/VoyateDBWithMaven" reloadable="true" source="org.eclipse.jst.jee.server:VoyateDBWithMaven"/></Host>
    </Engine>
  </Service>
</Server>

无论如何我可以解决这个问题以便可以访问资源吗?这很令人困惑,因为应用程序被部署并显示了索引文件。

【问题讨论】:

    标签: java rest maven tomcat netbeans


    【解决方案1】:

    无法打开资源 URL : localhost:8080//api/activity

    “localhost:8080”和“api/activity”之间有两个斜线。在您指定路径的配置中删除一个:api/activity 而不是 /api/activity

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2018-07-13
      相关资源
      最近更新 更多