나는 Jersey User Guide을보고 있으며 Jersey 웹 서비스와 내장 된 Grizzly 서버를 사용하여 Hello World 예제를 설정하려고합니다.Jersey와 Grizzly가있는 Hello World (사용자 가이드에서)
제 1 절 "시작하기"를 실행 중입니다. 나는이 내장 된 그리즐리 웹을 설정하는데있어 어디, "루트 자원을 배포",
// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP GET requests
@GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String getClichedMessage() {
// Return some cliched textual content
return "Hello World";
}
}
을하지만 그때 나는 1.2 절에 도착 : 나는 1.1 절 잘 컴파일에 코드 예제있어 서버 내 자원을 테스트합니다 :
public class Main {
public static void main(String[] args) throws IOException {
final String baseUri = "http://localhost:9998/";
final Map<String, String> initParams =
new HashMap<String, String>();
initParams.put("com.sun.jersey.config.property.packages",
"com.sun.jersey.samples.helloworld.resources");
System.out.println("Starting grizzly...");
SelectorThread threadSelector =
GrizzlyWebContainerFactory.create(baseUri, initParams);
System.out.println(String.format(
"Jersey app started with WADL available at %sapplication.wadl\n” +
“Try out %shelloworld\nHit enter to stop it...", baseUri, baseUri));
System.in.read();
threadSelector.stopEndpoint();
System.exit(0);
}
}
문제는,이 사용자 가이드는 한동안 업데이트되지 않은 것 같다 및 클래스 GrizzlyWebContainerFactory
는 더 이상 존재하지!
저는 Jersery v 1.10과 Grizzly v 1.9.41을 사용하고 있습니다.
누군가이 예제를 다시 만들 수있게 도와 줄 수 있습니까? 컨테이너에서 웹 서비스를 실행할 수 있다는 것을 알고, 내 프로젝트에 추가 리소스 (예 : web.xml 등)가 필요없는 가장 간단한 임베디드 서버 설정을 통해 실행하는 데 관심이 있습니다. 단 2 클래스입니다.
감사합니다. 이 문제를 해결하겠습니다. –
문제가 제기되었습니다. http://java.net/jira/browse/JERSEY-840 –
굉장! 나는 SO를 사용하고 이런 일이 일어나는 것을 보는 것을 좋아합니다! 바라건대 다른 Jersey 초보자에게 혼란을 피하는 데 도움이 될 것입니다. –