RESTful 자바 패턴과 실전 응용 - 바크티 메타 지음, 이일웅 옮김/에이콘출판 |
책의 샘플 소스는 GlassFish에서 실행하는 방법을 안내하고 있다. GlassFish는 써본 적이 없기 때문에, Tomcat에서 실행했지만 쉽지 않았다. 결과적으로 pom.xml에서 일부 dependency의 scope을 변경하고, 신규 dependency를 추가하여 실행할 수 있었다.
실행환경
- Windows 7 Professional K- IntelliJ IDEA Ultimate 2017.2
- Tomcat 8.5.16
chapter01. helloworld
샘플 소스에는 IntelliJ IDEA 기반 설정파일이 포함되어 있다. 그 파일은 제외하고 pom.xml만으로 IntelliJ의 모듈을 생성한 후, pom.xml을 아래와 같이 수정했다.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>helloworld</groupId> <artifactId>helloworld</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <description>Basic "helloworld" sample</description> <dependencies> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.0-rc2</version> <!--<scope>provided</scope>--> <scope>compile</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> <version>7.0</version> <!--<scope>provided</scope>--> <scope>compile</scope> </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.1.0.Beta2</version> <!--<scope>provided</scope>--> <scope>compile</scope> </dependency> <dependency> <groupId>org.glassfish.jersey.ext</groupId> <artifactId>jersey-bean-validation</artifactId> <!--<version>2.1</version>--> <version>2.9</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-moxy</artifactId> <version>2.9</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet-core</artifactId> <version>2.9</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.9</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.glassfish.jersey.bundles.repackaged</groupId> <artifactId>jersey-guava</artifactId> <version>2.9</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1-beta-1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> <finalName>helloworld</finalName> </build> </project> |
chapter03. exception-mapper / jax-rs-bean-validation
json 형태로 수신한 데이터를 처리할 때, 아래와 같은 에러가 발생한다.
24-Aug-2017 11:18:33.020 심각 [http-nio-8090-exec-1] org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom MessageBodyReader not found for media type=application/json, type=class org.coffeeshop.Coffee, genericType=class org.coffeeshop.Coffee.
pom.xml에 jersey-media-json-jackson 라이브러리 의존성을 추가하면 정상 동작한다.
1 2 3 4 5 6 | <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.9</version> <scope>compile</scope> </dependency> |
Chapter05. pagination
JsonProvider 구현체가 없어서 아래와 같은 에러가 발생한다.javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found javax.json.spi.JsonProvider.provider(JsonProvider.java:97) javax.json.Json.createGenerator(Json.java:114) org.coffeeshop.CoffeeCollectionWriter.writeTo(CoffeeCollectionWriter.java:44) org.coffeeshop.CoffeeCollectionWriter.writeTo(CoffeeCollectionWriter.java:27) org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:263)
pom.xml에 javax.json 라이브러리를 추가하면 정상 동작한다.
1 2 3 4 5 6 | <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.json</artifactId> <version>1.0.4</version> <scope>compile</scope> </dependency> |
0 댓글