How do I migrate from Jersey 1.0 to Jersey 2.0?

前端 未结 5 1399
旧时难觅i
旧时难觅i 2021-02-05 06:07

I\'m trying to upgrade to Jersey 2.0 and I\'m having a lot of trouble because the groupIds and artifactIds of Jersey have completely changed and I can\'t find a migration plan i

5条回答
  •  -上瘾入骨i
    2021-02-05 06:44

    It looks like @InjectLink is the replacement for @Ref.

    From that link, I was able to drop this into my pom.xml:

        
            org.glassfish.jersey.ext
            jersey-declarative-linking
            2.6
        
    

    and then I took an existing @Ref and was able to drop in replace with @InjectLink.

    public Long id; // This id is referenced below in the link
    
    @InjectLink(resource = FavoriteResource.class, method = "updateFavorites", bindings = {
            @Binding(name = "listId", value = "${instance.id}")
    })
    public URI linkURI;
    

    It looks like some of the JavaDocs from @Ref are in @InjectLink even, which would be further confirmation that it's the replacement:

    /**
     * ...
     * @Ref(resource=SomeResource.class)
     * @Ref(resource=SomeResource.class, bindings={
     *   @Binding(name="id" value="${instance.id}"}
     * )
    */
    

    EDIT:

    Tricky stuff. I needed one more piece to make this work for me. In web.xml, I now have:

    
        jersey-servlet
        org.glassfish.jersey.servlet.ServletContainer
        
            jersey.config.server.provider.packages
            com.mycompany.root
        
        
            jersey.config.server.provider.classnames
            com.mycompany.root.web.filter.AuditResourceFilterFactory;com.mycompany.root.web.filter.OtherAuditResourceFilterFactory
        
        
            javax.ws.rs.Application
            com.mycompany.root.web.resource.config.CustomResourceConfig
        
        1
    
    

    and finally, CustomResourceConfig.java looks like this

    import org.glassfish.jersey.linking.DeclarativeLinkingFeature;
    import org.glassfish.jersey.server.ResourceConfig;
    
    public class CustomResourceConfig extends ResourceConfig {
        public CustomResourceConfig() {
            packages("org.glassfish.jersey.examples.linking");
            register(DeclarativeLinkingFeature.class);
        }
    }
    

提交回复
热议问题