更新:奇怪的是,仅当我使用Gradle构建jar时才会引发此错误。Maven生成的jar运行良好!因此,我目前正在研究gradle构建脚本/ spring boot配置是否以及如何失败。
我有一个Spring Boot应用程序抛出以下错误
========================= AUTO-CONFIGURATION REPORT ========================= Positive matches: ----------------- DataSourceAutoConfiguration - @ConditionalOnClass classes found: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition) DataSourceAutoConfiguration.DataSourceInitializerConfiguration - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer; SearchStrategy: all) found no beans (OnBeanCondition) DataSourceTransactionManagerAutoConfiguration - @ConditionalOnClass classes found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition) DataSourceTransactionManagerAutoConfiguration.TransactionManagementConfiguration - @ConditionalOnMissingBean (types: org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration; SearchStrategy: all) found no beans (OnBeanCondition) DispatcherServletAutoConfiguration - found web application StandardServletEnvironment (OnWebApplicationCondition) - @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition) DispatcherServletAutoConfiguration.DispatcherServletConfiguration - no ServletRegistrationBean found (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition) - @ConditionalOnClass classes found: javax.servlet.ServletRegistration (OnClassCondition) EmbeddedServletContainerAutoConfiguration - found web application StandardServletEnvironment (OnWebApplicationCondition) EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat - @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat (OnClassCondition) - @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: current) found no beans (OnBeanCondition) ErrorMvcAutoConfiguration - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet (OnClassCondition) - found web application StandardServletEnvironment (OnWebApplicationCondition) ErrorMvcAutoConfiguration#basicErrorController - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.ErrorController; SearchStrategy: current) found no beans (OnBeanCondition) ErrorMvcAutoConfiguration#errorAttributes - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.ErrorAttributes; SearchStrategy: current) found no beans (OnBeanCondition) ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration - No error template view detected (ErrorMvcAutoConfiguration.ErrorTemplateMissingCondition) - SpEL expression on org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration: ${error.whitelabel.enabled:true} (OnExpressionCondition) ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration#beanNameViewResolver - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.BeanNameViewResolver; SearchStrategy: all) found no beans (OnBeanCondition) ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration#defaultErrorView - @ConditionalOnMissingBean (names: error; SearchStrategy: all) found no beans (OnBeanCondition) HttpMessageConvertersAutoConfiguration - @ConditionalOnClass classes found: org.springframework.http.converter.HttpMessageConverter (OnClassCondition) HttpMessageConvertersAutoConfiguration#messageConverters - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.HttpMessageConverters; SearchStrategy: all) found no beans (OnBeanCondition) HttpMessageConvertersAutoConfiguration.ObjectMappers - @ConditionalOnClass classes found: com.fasterxml.jackson.databind.ObjectMapper (OnClassCondition) HttpMessageConvertersAutoConfiguration.ObjectMappers#mappingJackson2HttpMessageConverter - @ConditionalOnMissingBean (types: org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; SearchStrategy: all) found no beans (OnBeanCondition) JacksonAutoConfiguration - @ConditionalOnClass classes found: com.fasterxml.jackson.databind.ObjectMapper (OnClassCondition) JacksonAutoConfiguration.JacksonObjectMapperAutoConfiguration - @ConditionalOnClass classes found: com.fasterxml.jackson.databind.ObjectMapper (OnClassCondition) JmxAutoConfiguration - @ConditionalOnClass classes found: org.springframework.jmx.export.MBeanExporter (OnClassCondition) - SpEL expression on org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration: ${spring.jmx.enabled:true} (OnExpressionCondition) JmxAutoConfiguration#mbeanServer - @ConditionalOnMissingBean (types: javax.management.MBeanServer; SearchStrategy: all) found no beans (OnBeanCondition) MultipartAutoConfiguration - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver,javax.servlet.MultipartConfigElement (OnClassCondition) - SpEL expression on org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration: ${multipart.enabled:true} (OnExpressionCondition) MultipartAutoConfiguration#multipartConfigElement - @ConditionalOnMissingBean (types: javax.servlet.MultipartConfigElement; SearchStrategy: all) found no beans (OnBeanCondition) MultipartAutoConfiguration#multipartResolver - @ConditionalOnMissingBean (types: org.springframework.web.multipart.support.StandardServletMultipartResolver; SearchStrategy: all) found no beans (OnBeanCondition) ServerPropertiesAutoConfiguration - found web application StandardServletEnvironment (OnWebApplicationCondition) ServerPropertiesAutoConfiguration#serverProperties - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.ServerProperties; SearchStrategy: current) found no beans (OnBeanCondition) WebMvcAutoConfiguration - found web application StandardServletEnvironment (OnWebApplicationCondition) - @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter (OnClassCondition) - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) found no beans (OnBeanCondition) WebMvcAutoConfiguration#hiddenHttpMethodFilter - @ConditionalOnMissingBean (types: org.springframework.web.filter.HiddenHttpMethodFilter; SearchStrategy: all) found no beans (OnBeanCondition) WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beanNameViewResolver - @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found the following [error] (OnBeanCondition) WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver - @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy: all) found no beans (OnBeanCondition) WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#requestContextListener - @ConditionalOnMissingBean (types: org.springframework.web.context.request.RequestContextListener; SearchStrategy: all) found no beans (OnBeanCondition) WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver - @ConditionalOnBean (types: org.springframework.web.servlet.ViewResolver; SearchStrategy: all) found the following [beanNameViewResolver, defaultViewResolver] @ConditionalOnMissingBean (names: viewResolver; SearchStrategy: all) found no beans (OnBeanCondition) Negative matches: ----------------- .... .... WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#dateFormatter - @ConditionalOnProperty missing required properties: date-format not found (OnPropertyCondition) WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#localeResolver - @ConditionalOnMissingBean (types: org.springframework.web.servlet.LocaleResolver; SearchStrategy: all) found no beans (OnBeanCondition) - @ConditionalOnProperty missing required properties: locale not found (OnPropertyCondition) WebSocketAutoConfiguration - required @ConditionalOnClass classes not found: org.springframework.web.socket.WebSocketHandler,org.apache.tomcat.websocket.server.WsSci (OnClassCondition) 15:11:13.684 [main] ERROR o.s.boot.SpringApplication - Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762) ~[spring-context-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109) ~[spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE] Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1554) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:952) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE] Disconnected from the target VM, address: '127.0.0.1:61052', transport: 'socket' at org.springframework.boot.SpringApplication.run(SpringApplication.java:941) [spring-boot-1.1.6.RELEASE.jar:1.1.6.RELEASE] at org.ihc.phr.status.Initializer.main(Initializer.java:17) [main/:na] Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762) at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) ~[na:1.8.0_20] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.SpringApplication.run(SpringApplication.java:952) at org.springframework.boot.SpringApplication.run(SpringApplication.java:941) at org.ihc.phr.status.Initializer.main(Initializer.java:17) Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724) at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531) ~[na:1.8.0_20] at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) ~[na:1.8.0_20] at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355) at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) ~[na:1.8.0_20] at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286) at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120) ~[na:1.8.0_20] at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72) ~[na:1.8.0_20] at java.lang.Class.createAnnotationData(Class.java:3508) at java.lang.Class.createAnnotationData(Class.java:3508) ~[na:1.8.0_20] at java.lang.Class.annotationData(Class.java:3497) at java.lang.Class.createAnnotationData(Class.java:3513) at java.lang.Class.annotationData(Class.java:3497) at java.lang.Class.getDeclaredAnnotations(Class.java:3464) at org.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:352) at java.lang.Class.annotationData(Class.java:3497) ~[na:1.8.0_20] at org.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:319) at java.lang.Class.createAnnotationData(Class.java:3513) ~[na:1.8.0_20] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.isHandler(RequestMappingHandlerMapping.java:173) at java.lang.Class.annotationData(Class.java:3497) ~[na:1.8.0_20] at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:123) at java.lang.Class.getDeclaredAnnotations(Class.java:3464) ~[na:1.8.0_20] at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:103) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:126) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613) at org.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:352) ~[spring-core-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550) ... 15 more at org.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:319) ~[spring-core-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.isHandler(RequestMappingHandlerMapping.java:173) ~[spring-webmvc-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:123) ~[spring-webmvc-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:103) ~[spring-webmvc-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:126) ~[spring-webmvc-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE] ... 15 common frames omitted :bootRun FAILED FAILURE: Build failed with an exception.
初始化器:
@Configuration @ComponentScan(basePackages={"com.mycompany", "com.mycompany.utils", "com.mycompany.domain","com.mycompany.resources", "com.mycompany.resources.hook"}) @EnableAutoConfiguration public class Initializer { public static void main(String[] args) { SpringApplication.run(Initializer.class, args); } }
配置类
@Configuration @EnableAsync @EnableScheduling @PropertySource("classpath:application-dev.properties") @ImportResource(value="classpath:applicationContext.xml") @ComponentScan(basePackages={ "com.mycompany.web"}) public class StatusConfiguration { @Autowired Environment env; @Bean public ObjectMapper jacksonObjectMapper() { return new CustomObjectMapper(); } @Bean public TargetServer targetServer(){ TargetServer targetServer = new TargetServer(); targetServer.setJndiValidationConnectionURL(env.getProperty("jndiValidationConnectionURL")); targetServer.setJndiValidationUsername(env.getProperty("jndiValidationUsername")); targetServer.setJndiValidationPassword(env.getProperty("jndiValidationPassword")); return targetServer; } }
控制者
@RestController public class StatusController { @Autowired private ReportService reportService; @Autowired private TargetServer targetServer; private Logger log = LoggerFactory.getLogger(StatusController.class); @RequestMapping(value = "/report") public MyReport getStatus(){ MyReport report = reportService.getReport(); return report; } @RequestMapping(value = "/report/no-cache") public MyReport getStatusNoCache(){ autoRunReport(); MyReport report = reportService.getReport(); return report; } @Scheduled(fixedDelay=300000) public void autoRunReport(){ reportService.kickOffReport(targetServer); log.debug("Running the scheduled validation Report!"); } }
Gradle配置
apply plugin: 'java' apply plugin: 'maven' apply plugin: 'spring-boot' dependencies { compile("org.springframework.boot:spring-boot-starter-web:1.1.6.RELEASE") compile(group: 'org.ihc.mh', name: 'mh-util', version:'13.12.5') { exclude(module: 'slf4j-api') exclude(module: 'slf4j-log4j12') } /* testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'1.1.6.RELEASE') { exclude(module: 'commons-logging') }*/ } buildscript { dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE") } } /* idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } }*/
另外,如果我直接运行Initializer(作为Java可执行类),则运行良好。但是,当我将其打包为jar并运行jar文件时,此操作将失败。任何帮助/见解表示赞赏。
Gradle和Maven依赖库文件夹之间的差异
Only in Gradle Build: commons-logging-1.1.3.jar Only in Gradle Build: jackson-annotations-2.3.0.jar Only in Gradle Build: spring-boot-starter-security-1.1.6.RELEASE.jar Only in Gradle Build: spring-context-support-3.0.5.RELEASE.jar Only in Gradle Build: spring-jdbc-3.0.5.RELEASE.jar Only in Gradle Build: spring-security-config-3.2.5.RELEASE.jar Only in Gradle Build: spring-security-core-3.2.5.RELEASE.jar Only in Gradle Build: spring-security-web-3.2.5.RELEASE.jar Only in Gradle Build: spring-tx-3.0.5.RELEASE.jar Only in Maven Build: jackson-annotations-2.3.4.jar Only in Maven Build: spring-context-support-4.0.7.RELEASE.jar Only in Maven Build: spring-jdbc-4.0.7.RELEASE.jar Only in Maven Build: spring-tx-4.0.7.RELEASE.jar
我们(Spring Boot团队)之前已经看到过这种问题。不幸的是,JVM的诊断确实很差。它试图告诉您的是,它遇到了一个带有Class []属性的注释,该注释引用的类不在classpath上。如果它告诉您缺少的课程是什么,那将是非常有用的。
我尝试使用上面的代码片段重现您的失败,但是无法这样做。在使用Maven进行此工作时,请尝试查看unzip -l使用Maven和Gradle构建的jar的运行输出,看看是否可以发现Gradle案例中缺少的内容。
unzip -l