TomEE 1.7.2,Java 6,Java8
我有这个JAX-RS应用程序:
@ApplicationPath("/api")
public class CallStatsCatcherApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(RestEndpoint.class));
}
}
@ApplicationScoped
@Path("/rest")
public class RestEndpoint {
@GET
public String echo(@QueryParam("foo") String foo) {
return foo;
}
}
启动期间,TomEE打印:
INFO: GET http://localhost:8080/test-application/api/rest/ -> String echo(String)
如何在启动期间以编程方式获得?我想要创建一个框架,在网络上本地广告这个URL。
发布于 2015-12-07 15:48:17
要获得服务器入口部分,您可以尝试使用类似的方法:Java :如何获取我的应用程序的URL?
但是,如果您需要启动bean中的IP地址,可以尝试使用:
InetAddress ip = InetAddress.getLocalHost();
String ipAddress = ip.getHostAddress();`
另一种选择是使用:
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer()`
但是它可能与服务器平台相关联,您需要搜索该属性。
发布于 2015-12-07 16:27:12
您可以结合使用UriInfo类和UriBuilder类来使用当前路径挂载或创建URL。
堆栈溢出中也存在类似的问题:得到基地网址..。
https://stackoverflow.com/questions/34144348
复制