我是新来指定Java中的资源路线,我有指定路线的问题。到目前为止,我有一个简单扩展Application的类,以及一个可以反应输入的类。这些类的路由要求是什么?我的下面的代码不起作用,我试图找出原因。我试图找到这些来源,但没有多少运气。@Path注解要求?
我可以只使用/作为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 {...}
}
2017-07-31
Rilcon42
+0
请让你的问题更清楚。你有什么问题? _“我可以只使用/为ApplicationPath”_ - 我认为这是个坏主意,因为你可以用'@ Path'来创建一堆类,并且你想要清除(没有交集)路由到这个类。对于你想要路由到的类中的方法,最好在你的class和'@ Path'上有一个'@ Path'。 –