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
pull/1695/merge
Andy Wilkinson 10 years ago
parent c90633aab6
commit 2b7bf3e733

@ -19,11 +19,9 @@ package org.springframework.boot.autoconfigure.jersey;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.ws.rs.ApplicationPath; import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spring.SpringComponentProvider;
import org.glassfish.jersey.servlet.ServletContainer; import org.glassfish.jersey.servlet.ServletContainer;
import org.glassfish.jersey.servlet.ServletProperties; import org.glassfish.jersey.servlet.ServletProperties;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
@ -48,9 +46,12 @@ import org.springframework.web.filter.RequestContextFilter;
* {@link EnableAutoConfiguration Auto-configuration} for Jersey. * {@link EnableAutoConfiguration Auto-configuration} for Jersey.
* *
* @author Dave Syer * @author Dave Syer
* @author Andy Wilkinson
*/ */
@Configuration @Configuration
@ConditionalOnClass({ SpringComponentProvider.class, ServletRegistration.class }) @ConditionalOnClass(name = {
"org.glassfish.jersey.server.spring.SpringComponentProvider",
"javax.servlet.ServletRegistration" })
@ConditionalOnBean(ResourceConfig.class) @ConditionalOnBean(ResourceConfig.class)
@ConditionalOnWebApplication @ConditionalOnWebApplication
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)

Loading…
Cancel
Save