From 2b7bf3e73359e0b5d7e31b899f638df2c9d30c43 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 13 Oct 2014 11:16:55 +0100 Subject: [PATCH] Fix ArrayStoreException caused by JerseyAutoConfiguration JerseyAutoConfiguration is annotated with @ConditionalOnClass. It references both SpringComponentProvider.class and ServletRegistration.class. Normally, this wouldn't be a problem as, in the absence of either of those classes, the configuration class bean will not be present in the bean factory and, therefore, its annotations will never be introspected using reflection. However, JerseyAutoConfiguration is a WebApplicationInitializer. This means that when it's deployed to a standalone container, JerseyAutoConfiguration is found by the container and its class is passed to SpringServletContainerInitializer. SpringServletContainerInitializer introspects every WebApplicationInitializer class so that it can order them. This blows up if Jersey's SpringComponentProvider class isn't on the classpath as the annotation is referencing SpringComponentProvider as a Class and the attempt to load it fails. The problem can be avoided by referencing SpringComponentProvider using a String. Fixes gh-1696 --- .../boot/autoconfigure/jersey/JerseyAutoConfiguration.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java index 55bbd92d871..de2a106c778 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jersey/JerseyAutoConfiguration.java @@ -19,11 +19,9 @@ package org.springframework.boot.autoconfigure.jersey; import javax.annotation.PostConstruct; import javax.servlet.ServletContext; import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; import javax.ws.rs.ApplicationPath; import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.server.spring.SpringComponentProvider; import org.glassfish.jersey.servlet.ServletContainer; import org.glassfish.jersey.servlet.ServletProperties; import org.springframework.beans.factory.ListableBeanFactory; @@ -48,9 +46,12 @@ import org.springframework.web.filter.RequestContextFilter; * {@link EnableAutoConfiguration Auto-configuration} for Jersey. * * @author Dave Syer + * @author Andy Wilkinson */ @Configuration -@ConditionalOnClass({ SpringComponentProvider.class, ServletRegistration.class }) +@ConditionalOnClass(name = { + "org.glassfish.jersey.server.spring.SpringComponentProvider", + "javax.servlet.ServletRegistration" }) @ConditionalOnBean(ResourceConfig.class) @ConditionalOnWebApplication @Order(Ordered.HIGHEST_PRECEDENCE)