※ 途中で投稿されていました。すみません。
jersey の ResourceConfig を継承した、Configクラスに、@Configuration アノテーションをつけるとランタイムエラーになります。
Java
1package myapi.config; 2 3import org.glassfish.jersey.server.ResourceConfig; 4import org.springframework.context.annotation.Configuration; 5 6import myapi.service.HelloService; 7 8// @Configuration // <- ここのコメント外すとエラー 9public class JerseyConfig extends ResourceConfig 10{ 11 public JerseyConfig() 12 { 13 register(HelloService.class); 14 } 15}
エラー内容(gradle build のtestタスク):StackTraceの一部は加工しています
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jerseyConfig' defined in file [***/config/JerseyConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [myapi.config.JerseyConfig$$EnhancerBySpringCGLIB$$db4dedf9]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/google/common/base/Function 2019-05-01 06:55:26.141 ERROR 22121 --- [ Test worker] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@7a5b8ae1] to prepare test instance [rex.hows.jsb.jsbhows.DemoApplicationTests@7183be67] java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jerseyConfig' defined in file [***/config/JerseyConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [myapi.config.JerseyConfig$$EnhancerBySpringCGLIB$$db4dedf9]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/google/common/base/Function Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [myapi.config.JerseyConfig$$EnhancerBySpringCGLIB$$db4dedf9]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/google/common/base/Function Caused by: java.lang.NoClassDefFoundError: com/google/common/base/Function at org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:338) ~[jaxrs-ri-2.0.1.jar:2.0.] at myapi.JerseyConfig.<init>(JerseyConfig.java:12) ~[main/:na] at myapi.config.JerseyConfig$$EnhancerBySpringCGLIB$$db4dedf9.<init>(<generated>) ~[main/:na] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na] Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
設定等疑わしいところアドバイスいただけたらと思います。
HelloService.java
Java
1package myapi.service; 2 3import javax.ws.rs.GET; 4import javax.ws.rs.Path; 5import javax.ws.rs.Produces; 6import javax.ws.rs.core.MediaType; 7 8import org.springframework.stereotype.Service; 9@Service 10@Path("/jax-rs") 11public class HelloService 12{ 13 @GET 14 @Produces(MediaType.APPLICATION_JSON) 15 public HelloResponse hello() 16 { 17 HelloResponse res = new HelloResponse(); 18 res.setResult("AAA"); 19 return res; 20 } 21}
HelloResponse.java
Java
1package myapi.response; 2 3import lombok.Getter; 4import lombok.NoArgsConstructor; 5import lombok.Setter; 6 7@NoArgsConstructor 8public class HelloResponse 9{ 10 11 @Getter 12 @Setter 13 public String result; 14}
回答1件
あなたの回答
tips
プレビュー