2014-05-03 36 views
0

我的行家模塊pom.xml看起來像Jersey:我是否也需要對JSR有Maven依賴關係?爲什麼?

<dependencies> 
    <dependency> 
     <groupId>org.glassfish.jersey.core</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>2.7</version> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.jersey.ext</groupId> 
     <artifactId>jersey-spring3</artifactId> 
     <version>2.8</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey.test.framework</groupId> 
     <artifactId>jersey-test-framework</artifactId> 
     <version>1.0.3.1</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

和資源類作爲

@Service 
@Path("/hello") 
public class HelloResource { 

    @GET 
    public Response hello() { 
     return Response.ok("Hello World!").build(); 
    } 
} 

這一切工作正常。
問題
- 我剛纔看到這個post,它說

同時需要JSR和實施。註釋在 JSR中,實現提供配套類

我可以知道爲什麼需要這個嗎?

回答

1

您在那裏的依賴關係將通過Maven傳遞依賴機制檢索JSR API jar。所以,如果你問爲什麼這很好,那是因爲jax.ws.rs-api 2.0將可以通過jersey-server-> jersey-common-> jax.ws.rs-api路徑獲得。

如果你問爲什麼兩個都需要(即使通過Maven傳遞依賴機制),那麼我會相信原因是API和實現之間的分離。您的代碼在編譯時依賴於JSR API,但在運行時它也需要實現。因此,從理論上講,可以在不影響代碼的情況下將一個實現替換爲另一個實現。

+0

這很有道理,謝謝 – daydreamer

相關問題