> For the complete documentation index, see [llms.txt](https://wannaqueen.gitbook.io/spring5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wannaqueen.gitbook.io/spring5/spring-boot/undefined-1/29./29.3-jax-rs-and-jersey.md).

# 29.3 JAX-RS and Jersey

**REST 엔드 포인트 용 JAX-RS 프로그래밍 모델을 선호한다면** Spring MVC 대신 사용 가능한 구현 중 하나를 사용할 수있다. [Jersey](https://jersey.github.io/) 와 [Apache CXF](https://cxf.apache.org/)work는 매우 잘 어울립니다. CXF를 사용하려면 응용 프로그램 컨텍스트에서 `@Bean`으로 `Servlet`또는 `Filter`를 등록해야합니다. **Jersey에는 기본 Spring 지원이 있으므로 Spring Boot에서 자동 구성 지원을 시작과 함께 제공**합니다.&#x20;

{% hint style="info" %}
Jersey&#x20;

Sun의 311에서 구현된 JAX-RS: RESTful 웹 서비스용 Java API&#x20;

* JAVA SE5에 소개된 어노테이션을 사용하여 정의된 사양 (대표적인 어노테이션으로 @Path, @GET, @POST, @PUT)

JSR-311에서 정의된 내용을 가지고 있기 때문에 개발자는 java 및 java JVM으로 Restful 웹 서비스를 쉽게 작성할 수 있음.&#x20;

JSR에서 지정하지 않은 추가 기능도 지원
{% endhint %}

**Jersey를 시작하려면 `spring-boot-starter-jersey`를 종속성으로 포함**시킨 다음, 다음 예와 같이 **모든 끝점을 등록하는 `ResourceConfig`유형의 `@Bean`이 하나 필요합니다.**

```java
@Component
public class JerseyConfig extends ResourceConfig {

	public JerseyConfig() {
		register(Endpoint.class);
	}

}
```

| ![\[Warning\]](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/images/warning.png)                                                                                                                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Jersey는 실행 가능한 아카이브 검사에 대한 지원을 제한합니다. 예를 들어, 실행 가능 war 파일을 실행할 때 `WEB-INF/classes`에있는 [fully executable jar file](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#deployment-install)에있는 패키지의 엔드 포인트를 스캔 할 수 없습니다. 이 제한을 피하려면 패키지 메소드를 사용하면 안되며, 앞의 예제와 같이 `register`메소드를 사용하여 엔드 포인트를 개별적으로 등록해야합니다. |

고급 사용자 정의를 위해 `ResourceConfigCustomizer`를 구현하는 임의의 수의 Bean을 등록 할 수도 있습니다.&#x20;

다음 예와 같이 **등록된 모든 엔드 포인트는 HTTP 자원 주석 (`@GET` 및 기타)이있는 `@Components` 여야합니다.**&#x20;

```java
@Component
@Path("/hello")
public class Endpoint {

	@GET
	public String message() {
		return "Hello";
	}

}
```

**`Endpoint`는 Spring `@Component`이므로 Spring의 라이프 사이클을 관리하고 `@Autowired`주석을 사용하여 종속성을 주입하고 `@Value` 주석을 사용하여 외부 구성을 주입 할 수 있습니다. 기본적으로 Jersey 서블릿은 등록되고 `/*`에 매핑됩니다.** `ResourceConfig`에 `@ApplicationPath`를 추가하여 매핑을 변경할 수 있습니다.&#x20;

기본적으로 Jersey는 `jerseyServletRegistration`이라는 `jerseyServletRegistration`유형의 @Bean에 서블릿으로 설정됩니다. 기본적으로 서블릿은 느리게 초기화되지만 `spring.jersey.servlet.load-on-startup`을 설정하여 해당 동작을 사용자 정의 할 수 있습니다. 동일한 이름으로 고유 한 bean을 작성하여 해당 bean을 사용 불가능하게하거나 대체 할 수 있습니다. `spring.jersey.type=filter`를 설정하여 서블릿 대신 필터를 사용할 수도 있습니다 (이 경우 교체하거나 무시할 `@Bean`은 `jerseyFilterRegistration`입니다). 필터에는 `@Order`가 있으며 `spring.jersey.filter.order`를 사용하여 설정할 수 있습니다. 서블릿과 필터 등록 모두에 `spring.jersey.init.*`를 사용하여 속성의 맵을 지정하여 초기화 매개 변수를 제공 할 수 있습니다.&#x20;

[Jersey sample](https://github.com/spring-projects/spring-boot/tree/v2.1.5.RELEASE/spring-boot-samples/spring-boot-sample-jersey)이 있으므로 설정 방법을 볼 수 있습니다.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wannaqueen.gitbook.io/spring5/spring-boot/undefined-1/29./29.3-jax-rs-and-jersey.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
