Add native image support.
This commit is contained in:
@@ -44,6 +44,10 @@ import okhttp3.ConnectionPool;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
@@ -73,6 +77,7 @@ import org.springframework.security.oauth2.client.AuthorizedClientServiceOAuth2A
|
||||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
|
||||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
|
||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -373,3 +378,17 @@ public class FeignAutoConfiguration {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FeignHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
if (!ClassUtils.isPresent("feign.Feign", classLoader)) {
|
||||
return;
|
||||
}
|
||||
hints.reflection().registerType(TypeReference.of(FeignClientFactoryBean.class),
|
||||
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ import org.springframework.util.StringUtils;
|
||||
class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware {
|
||||
|
||||
// patterned after Spring Integration IntegrationComponentScanRegistrar
|
||||
// and RibbonClientsConfigurationRegistgrar
|
||||
// and RibbonClientsConfigurationRegistrar
|
||||
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import javax.lang.model.element.Modifier;
|
||||
|
||||
import org.springframework.aot.generate.GenerationContext;
|
||||
import org.springframework.aot.generate.MethodReference;
|
||||
import org.springframework.aot.hint.ProxyHints;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
@@ -100,16 +101,20 @@ public class FeignClientBeanFactoryInitializationAotProcessor
|
||||
@Override
|
||||
public void applyTo(GenerationContext generationContext,
|
||||
BeanFactoryInitializationCode beanFactoryInitializationCode) {
|
||||
ProxyHints proxyHints = generationContext.getRuntimeHints().proxies();
|
||||
Set<String> feignClientRegistrationMethods = feignClientBeanDefinitions.values().stream()
|
||||
.map(beanDefinition -> {
|
||||
Assert.notNull(beanDefinition, "beanDefinition cannot be null");
|
||||
Assert.isInstanceOf(GenericBeanDefinition.class, beanDefinition);
|
||||
GenericBeanDefinition registeredBeanDefinition = (GenericBeanDefinition) beanDefinition;
|
||||
MutablePropertyValues feignClientProperties = registeredBeanDefinition.getPropertyValues();
|
||||
String className = (String) feignClientProperties.get("type");
|
||||
Assert.notNull(className, "className cannot be null");
|
||||
Class clazz = ClassUtils.resolveClassName(className, null);
|
||||
proxyHints.registerJdkProxy(clazz);
|
||||
return beanFactoryInitializationCode.getMethods()
|
||||
.add(buildMethodName((String) feignClientProperties.get("type")),
|
||||
method -> generateFeignClientRegistrationMethod(method, feignClientProperties,
|
||||
registeredBeanDefinition))
|
||||
.add(buildMethodName(className), method -> generateFeignClientRegistrationMethod(method,
|
||||
feignClientProperties, registeredBeanDefinition))
|
||||
.getName();
|
||||
}).collect(Collectors.toSet());
|
||||
MethodReference initializerMethod = beanFactoryInitializationCode.getMethods()
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
||||
org.springframework.cloud.openfeign.FeignHints
|
||||
@@ -160,7 +160,6 @@ public class FeignAotTests {
|
||||
|
||||
}
|
||||
|
||||
// TODO: verify other annotation parameters
|
||||
@FeignClient(value = "test-with-config", configuration = TestConfiguration.class)
|
||||
interface TestFeignClientWithConfig {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user