我有 2 个 grizzly 应用程序,我想在同一服务器上的不同 URL 上并排运行。当我将我的 url 从更改localhost
为api.url.local
进行本地调试时,它会抛出一个java.nio.channels.UnresolvedAddressException
. 为了让 java 识别另一个 URL(即 - 修改主机文件),我需要做些什么吗?还是我走错了方向?
我目前在 Windows 上,但将部署到 Linux。(如果由我决定,我会运行 Linux)
public class Main {
public static final URI BASE_URI = getBaseURI();
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost/").port(9998).build();
}
protected static HttpServer startServer() throws IOException {
ResourceConfig rc = new PackagesResourceConfig("com.my.package.api.resources");
rc.getFeatures()
.put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
}
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext annotationCtx = new AnnotationConfigApplicationContext(Config.class);
HttpServer httpServer = startServer();
System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nHit enter to stop it...", BASE_URI, BASE_URI));
System.in.read();
httpServer.stop();
}
}