microsoft / azure-spring-boot

Spring Boot Starters for Azure services
MIT License
374 stars 460 forks source link

@ConditionalOnClass should be used at configuration class level #730

Closed jialindai closed 5 years ago

jialindai commented 5 years ago

In AlwaysEncryptedAutoConfiguration, @ConditionalOnClass is used on bean method level. If the class referenced by the annotation is not in classpath, some exception is thrown. @ConditionalOnClass should be used on configration class level.

jialindai commented 5 years ago

Exception:

java.lang.IllegalStateException: Cannot load configuration class: com.microsoft.azure.spring.autoconfigure.sqlserver.AlwaysEncryptedAutoConfiguration$AlwaysEncryptedDataSourcePropertiesConfiguration at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:413) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:253) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:743) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:390) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE] at com.microsoft.azure.ServiceBindingCosmosDbApplication.main(ServiceBindingCosmosDbApplication.java:29) [classes/:na] Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) ~[na:1.8.0_221] at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) ~[na:1.8.0_221] at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) ~[na:1.8.0_221] at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) ~[na:1.8.0_221] at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_221] at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_221] at java.lang.reflect.Executable.declaredAnnotations(Executable.java:599) ~[na:1.8.0_221] at java.lang.reflect.Executable.declaredAnnotations(Executable.java:597) ~[na:1.8.0_221] at java.lang.reflect.Executable.getAnnotation(Executable.java:570) ~[na:1.8.0_221] at java.lang.reflect.Method.getAnnotation(Method.java:622) ~[na:1.8.0_221] at java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:258) ~[na:1.8.0_221] at java.lang.reflect.AccessibleObject.isAnnotationPresent(AccessibleObject.java:191) ~[na:1.8.0_221] at org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation(AnnotatedElementUtils.java:599) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.BeanAnnotationHelper.isBeanAnnotated(BeanAnnotationHelper.java:41) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.isMatch(ConfigurationClassEnhancer.java:439) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$ConditionalCallbackFilter.accept(ConfigurationClassEnhancer.java:192) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.proxy.Enhancer.emitMethods(Enhancer.java:1214) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:723) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanFactoryAwareGeneratorStrategy.generate(ConfigurationClassEnhancer.java:252) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:358) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_221] at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:416) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:402) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE] ... 12 common frames omitted

superrdean commented 5 years ago

Thanks for your feedback, we will inspect it later.

superrdean commented 5 years ago

@LGDoor you referred a wrong issue, your issue should refer to #729

superrdean commented 5 years ago

735 this PR has fixed the issue

LGDoor commented 5 years ago

@LGDoor you referred a wrong issue, your issue should refer to #729

Both issues prevent this sample from working.

superrdean commented 5 years ago

this problem has been fixed.