【问题标题】:Cannot find symbol PathParam in Jersey在泽西岛找不到符号 PathParam
【发布时间】:2015-05-16 03:23:00
【问题描述】:

这是我的代码

@Path("/users/{id}")
public class MyResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getId(@PathParam("id") String id) {
        return "Getting Messages for User : " + id;
    }
}

我得到的只是

..MyResource.java:[17,29] error: cannot find symbol

到目前为止,我已经检查了这两个 https://confluence.atlassian.com/display/CLOVERKB/Maven+2+plugin+fails+with+cannot+find+symbol+exception+when+defining+two+locations+for+source+files

&这个

maven "cannot find symbol" message unhelpful

但没有任何成功。

编辑: pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.placeholder</groupId>
    <artifactId>edelivery-sp</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>edelivery-sp</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
        </dependency>
        <!-- uncomment this to get JSON support:
         <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
        </dependency>
        -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <inherited>true</inherited>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.placeholder.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <jersey.version>2.16</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

</project>

【问题讨论】:

  • 如果这是一个构建问题,你真的需要展示你的手掌。
  • 您缺少 jaxrs api 类,但这可能是由于缺少 jersey-core 库。取决于您使用的球衣版本 1.x 或 2.x
  • @ChrisHinshaw 你是说我的 pom 文件吗? pastebin.com/VCrXwjRr
  • 愚蠢的问题,但是你导入了吗? import javax.ws.rs.PathParam;
  • @peeskillet 是的,就是这样。在我检查的每个可能的教程中,我都忽略了它。想要重新发布它以将其标记为已回答?

标签: java maven jersey jax-rs


【解决方案1】:

我在您的链接中查看您的 pom.xml,看起来您正在使用我熟悉的 Maven 原型。您发布的代码是原型提供的唯一类。唯一的区别是,您添加了@PathParam(以及路径的更改)。在这种情况下,您仍然需要导入注释:-)

import javax.ws.rs.PathParam;

【讨论】:

  • 我遇到了非常类似的事情。问题实际上是 Eclipse 为我自动导入了一个不同的 PathParam:javax.websocket.server.PathParam。我所有的代码都在 Eclipse 下编译,但被 Maven 卡住了。当然,我想要 javax.ws.rs.PathParam。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-02
  • 1970-01-01
相关资源
最近更新 更多