項目使用了spring boot+jersay構建resful項目,可是在打jar包的時候出現以下錯誤:java
主要緣由是:JerseyConfig類裏面,經過package()函數來指定要掃描的包的路徑的話,會致使找不到對應的路徑.spring
解決方法:ide
mport org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spring.scope.RequestContextFilter;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import java.util.stream.Collectors;
/**
* Jersey配置類
* @author Walter Wong
*/
@Component
public class JerseyConfig extends ResourceConfig {
/**
* 掃描com.makeronly包,使其識別JAX-RS註解
*/
public JerseyConfig() {
register(RequestContextFilter.class);
//packages("com.makeronly");
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(Path.class));
scanner.addIncludeFilter(new AnnotationTypeFilter(Provider.class));
this.registerClasses(scanner.findCandidateComponents("com.makeronly").stream()
.map(beanDefinition -> ClassUtils
.resolveClassName(beanDefinition.getBeanClassName(), this.getClassLoader()))
.collect(Collectors.toSet()));
}
}
其中紅色部分爲掃描的路徑。函數