整合springboot+jersey,打包成jar,使用java -jar xxx.jar时,可能会出现:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration':
Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'jerseyConfig' defined in URL [jar:file:/*.jar!/BOOT-INF/classes!/*/JerseyConfig.class]:
Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [*.JerseyConfig $ $ EnhancerBySpringCGLIB$$4249ac02]:
Constructor threw exception; nested exception is org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: *.jar!\BOOT-INF\classes (系统找不到指定的路径。)
可能原因:
在jersey配置中,使用了packages函数,建议使用register函数。在官方文档中有提示:
Jersey’s support for scanning executable archives is rather limited. For example, it cannot scan for endpoints in a package found in WEB-INF/classes when running an executable war file. To avoid this limitation, the packages method should not be used and endpoints should be registered individually using the register method as shown above.

本文探讨了在SpringBoot项目中整合Jersey遇到的问题及解决方法。主要关注于使用jar包部署时出现的依赖错误,指出jersey配置中使用packages函数可能导致的问题,并建议使用register函数来注册端点。
2125

被折叠的 条评论
为什么被折叠?



