java.lang.reflect.InvocationTargetException

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

If you're unit testing, you should instantiate only the service and mock the dependencies. If you're testing integration, you should add all the mocking to the configurations file.

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

  • When using `spring-data-couchbase` 1.4.0.BUILD-SNAPSHOT with `spring-data-commons` 1.11.0.BUILD-SNAPSHOT, an assertion failure occurs when trying to access the repositoryBaseClass. ------------- {code:title=pom.xml} .. <!-- Spring Data, Couchbase --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-couchbase</artifactId> <version>1.4.0.BUILD-SNAPSHOT</version> <exclusions> <exclusion> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> <version>1.11.0.BUILD-SNAPSHOT</version> </dependency> ... {code} {code:title=CouchbaseConfiguration.groovy} @Configuration @EnableConfigurationProperties @ConfigurationProperties(prefix = "couchbase") @EnableCouchbaseRepositories class CouchbaseConfiguration extends AbstractCouchbaseConfiguration { List<String> hosts String bucketName String bucketPassword @Override protected List<String> bootstrapHosts() { return hosts } } {code} ---------------- On bootstrapping the application, The following exception occurs: {code} [WARNING] java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: Attribute 'repositoryBaseClass' not found at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:108) at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:89) at org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.getRepositoryBaseClassName(AnnotationRepositoryConfigurationSource.java:224) at org.springframework.data.repository.config.DefaultRepositoryConfiguration.getRepositoryBaseClassName(DefaultRepositoryConfiguration.java:159) at org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder.build(RepositoryBeanDefinitionBuilder.java:94) at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:128) at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:353) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:151) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) ... {code}
    via by A.J. Brown,
  • When using `spring-data-couchbase` 1.4.0.BUILD-SNAPSHOT with `spring-data-commons` 1.11.0.BUILD-SNAPSHOT, an assertion failure occurs when trying to access the repositoryBaseClass. ------------- {code:title=pom.xml} .. <!-- Spring Data, Couchbase --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-couchbase</artifactId> <version>1.4.0.BUILD-SNAPSHOT</version> <exclusions> <exclusion> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> <version>1.11.0.BUILD-SNAPSHOT</version> </dependency> ... {code} {code:title=CouchbaseConfiguration.groovy} @Configuration @EnableConfigurationProperties @ConfigurationProperties(prefix = "couchbase") @EnableCouchbaseRepositories class CouchbaseConfiguration extends AbstractCouchbaseConfiguration { List<String> hosts String bucketName String bucketPassword @Override protected List<String> bootstrapHosts() { return hosts } } {code} ---------------- On bootstrapping the application, The following exception occurs: {code} [WARNING] java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: Attribute 'repositoryBaseClass' not found at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:108) at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:89) at org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.getRepositoryBaseClassName(AnnotationRepositoryConfigurationSource.java:224) at org.springframework.data.repository.config.DefaultRepositoryConfiguration.getRepositoryBaseClassName(DefaultRepositoryConfiguration.java:159) at org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder.build(RepositoryBeanDefinitionBuilder.java:94) at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:128) at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:353) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:151) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) ... {code}
    via by A.J. Brown,
  • I'm trying to create a _composed annotation_ which uses {{@Configuration}} and {{@ComponentScan}} as meta-annotations. {code} @Configuration @ComponentScan @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface BennuSpringModule { String[] basePackages() default {}; String[] bundles() default {}; } {code} The problem appears in {{ConfigurationClassPostProcessor}}: {noformat} java.lang.IllegalArgumentException: Attribute 'nameGenerator' is of type [String], but [Class] was expected. Cause: at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117) at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:89) at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:82) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:236) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:241) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:152) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:299) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:530) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) at javax.servlet.GenericServlet.init(GenericServlet.java:160) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) {noformat} The meta-annotation is being processed with {{classValuesAsString}} set to {{true}} which breaks the look-up for Class Type. See [AnnotationAttributesReadingVisitor|https://github.com/spring-projects/spring-framework/blob/161819f1417579c915751a6ef1fa7699963574fb/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java#L282] for details.
    via by Sérgio Silva,
  • I'm trying to create a _composed annotation_ which uses {{@Configuration}} and {{@ComponentScan}} as meta-annotations. {code} @Configuration @ComponentScan @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface BennuSpringModule { String[] basePackages() default {}; String[] bundles() default {}; } {code} The problem appears in {{ConfigurationClassPostProcessor}}: {noformat} java.lang.IllegalArgumentException: Attribute 'nameGenerator' is of type [String], but [Class] was expected. Cause: at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117) at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:89) at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:82) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:236) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:241) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:152) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:299) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:530) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) at javax.servlet.GenericServlet.init(GenericServlet.java:160) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) {noformat} The meta-annotation is being processed with {{classValuesAsString}} set to {{true}} which breaks the look-up for Class Type. See [AnnotationAttributesReadingVisitor|https://github.com/spring-projects/spring-framework/blob/161819f1417579c915751a6ef1fa7699963574fb/spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java#L282] for details.
    via by Sérgio Silva,
  • Spring Boot test class wont inject beans
    via Stack Overflow by rayman
    ,
    • java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: Attribute 'repositoryBaseClass' not found at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:108) at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:89) at org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.getRepositoryBaseClassName(AnnotationRepositoryConfigurationSource.java:224) at org.springframework.data.repository.config.DefaultRepositoryConfiguration.getRepositoryBaseClassName(DefaultRepositoryConfiguration.java:159) at org.springframework.data.repository.config.RepositoryBeanDefinitionBuilder.build(RepositoryBeanDefinitionBuilder.java:94) at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:128) at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:83) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:353) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:151) at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:124) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:318) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)

    Users with the same issue

    derproggerderprogger
    2 times, last one,
    tomthomastomthomas
    121 times, last one,
    tvrmsmithtvrmsmith
    1 times, last one,
    osvzsosvzs
    2 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    189 more bugmates