整合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.