繁体   English   中英

@Path注释要求?

[英]@Path Annotation requirements?

我是Java中指定资源路由的新手,但是在指定路由时遇到了问题。 到目前为止,我有一个仅扩展Application类,以及一个对输入做出反应的类。 这些类的路由要求是什么? 我的以下代码无法正常工作,我试图找出原因。 我已经尝试找到这些资源的来源,但是运气并不好。

  1. 我可以仅将/用作ApplicationPath吗? 该类所做的只是扩展Application以便它可以找到路由。

例:

package com.sentiment360.helloworld;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

/**
 * JAXActivator is an arbitrary name, what is important is that javax.ws.rs.core.Application is extended
 * and the @ApplicationPath annotation is used with a "rest" path.  Without this the rest routes linked to
 * from index.html would not be found.
 */
@ApplicationPath("/")
public class JAXActivator extends Application {
}

每个类是否都需要有一个声明的@Path(或者它们都可以是@Stateless)?

@Path("/helloservice")
public class HelloService {

    private static Logger _logger;

    public HelloService(){
        _logger = Logger.getLogger(HelloService.class.getName());
    }

    private Connection conn() throws SQLException  {...}
}

#1的简短版本是。

但是:行为取决于实现。 有关详细说明,请参见https://stackoverflow.com/a/16747253/1063501

对于#2,是的,通常需要为每个所需的端点指定一个@Path 它是@Stateless的事实是无关紧要的,因为您需要一种解决它的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM