Spring boot error:java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
Asked Answered
S

10

38

I want to use spring boot to start my application ,but after i add some relative jar at pom.xml,it return this error:and i thank may be it caused by some conflict jars?

Application.java

package com.mm.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@ComponentScan("com.mm.controller")
@Configuration
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
    //spring properties xml
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "Spring-Module.xml");
    SpringApplication.run(Application.class, args);
}
@Bean
public InternalResourceViewResolver setupViewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/jsp/");
    resolver.setSuffix(".jsp");
    return resolver;
}

}

Error:

Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug)

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
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
atorg.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:898)
at com.mm.application.Application.main(Application.java:20)

Main Problem:

 Caused by: java.lang.ArrayStoreException:sun.reflect.annotation.TypeNotPresentExceptionProxy
atsun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:673)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:480)
atsun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:306)
atsun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241)
atsun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
atsun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3178)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3185)
at java.lang.Class.getDeclaredAnnotations(Class.java:3166)
atorg.springframework.core.annotation.AnnotationUtils.isAnnotationDeclaredLocally(AnnotationUtils.java:395)
atorg.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:281)
atorg.springframework.core.annotation.AnnotationUtils.findAnnotation(AnnotationUtils.java:265)
atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.isHandler(RequestMappingHandlerMapping.java:173)
atorg.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:123)
atorg.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:103)
atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:126)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 15 more

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.0.1.RELEASE</version>
</parent>



<properties>
    <start-class>com.kdubb.springboot.Application</start-class>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>http://repo.spring.io/libs-snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>http://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>http://repo.spring.io/libs-snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<dependencies>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.0.4</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-dao</artifactId>
        <version>2.0.8</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
</dependencies>

LoginController

package com.mm.controller;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@Component
public class LoginController {
@RequestMapping(value = "/CreditRating", method = RequestMethod.GET)
public String index(Model model) {
    model.addAttribute("wisdom", "Goodbye XML");
    // renders /WEB-INF/jsp/Login.jsp
    return "Login";
}

@RequestMapping(value = "/CreditRating/GoLogin")
public String login(Model model) {

    model.addAttribute("wisdom", "Goodbye XML");
    // renders /WEB-INF/jsp/index.jsp
    return "index";
}
}
Sturgill answered 22/6, 2014 at 15:55 Comment(10)
Why do you have explicit dependencies on spring-context and spring-dao?Bois
And why are you creating an XML application context before the SpringApplication?Bois
i just want to use spring+ mybatis,and create an XML application context to load the database propertiesSturgill
Then I guess the XML should be one of the sources in the SpringApplication? Try that and maybe you will find a more concrete problem to discuss.Bois
possible duplicate of java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy after moving to Android Annotations v.2.7Celerity
Did you solve this problem?. I am facing a similar situation and the link posted by Aaron Digulla does not offer a solution in my case because I am not using androidKildare
This may be a bug that has been already fixed: github.com/spring-projects/spring-boot/issues/1696Lichenin
I ran into this with an entirely different project, and the solution was to rebuild the whole project ... something got out of sync while doing incremental builds.Infer
I faced a similar issue and in my case I had to replace 'org.springframework.boot:spring-boot-actuator' with 'org.springframework.boot:spring-boot-actuator-autoconfigure' to resolve this.Gyneco
it can also occur in case if an annotation is referred but the jar is not thereTedmund
R
47

The solution can vary based on actual incompatibility root cause. The best way how to investigate such the issue is to follow this line:

Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

and put breakpoint into constructor of class 'TypeNotPresentExceptionProxy' (there is only one).

After execution in debug mode you should see what exactly is wrong and based on your findings you can decide what to do (add dependency, exclude autoconfig, ...)

In my specific case the breakpoint revealed this:

java.lang.ClassNotFoundException: org.springframework.integration.config.IntegrationManagementConfigurer

As the solution I decided to exclude 'IntegrationAutoConfiguration' like this:

@SpringBootApplication(exclude = IntegrationAutoConfiguration.class)
Ride answered 8/8, 2019 at 15:25 Comment(3)
that's actually the way you would find the root cause of this type of error.Mcabee
@Ride I want to put breakpoint into constructor of class 'TypeNotPresentExceptionProxy' . But when I try to do it I am getting Source not found. I am using Eclipse IDE.Pourparler
@KarthikPai try this #6175050Ride
S
20

As explained by Andy Wilkinson in this GitHub issue or in this thread, these obscure exceptions occur when some annotation is referencing a class that isn't on the classpath.

Most issues of this kind have been fixed in recent Spring Boot versions, but you can also trigger one from your code, for example when using @AutoConfigureAfter(X.class) where class X is missing on the classpath.

Selfdetermination answered 3/8, 2017 at 14:34 Comment(3)
Additionally, check github.com/spring-projects/spring-boot/issues/…. With a break point in TypeNotPresentExceptionProxy you can spot the missing class!Octroi
Thanks man. This was most usefull answer. Setting breakpoint there give me issued class.Underwrite
Thanks @Tobias, this link and hint helped me figure out the referenced class that was missing on the classpath. I did not have the source code for TypeNotPresentExceptionProxy, but I was able to set a breakpoint using the Outline view in Eclipse - right click on the constructor and toggle a breakpoint. The argument clearly states the name of the culprit.Tony
A
5

I had the same issue with spring-boot-starter-parent 2.0.0.M6.

The solution

was to remove

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
    <version>3.1.11</version>
</dependency>

and include

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>

instead.

Atharvaveda answered 24/11, 2017 at 13:30 Comment(0)
I
3

I had the same issue with :

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
   </parent>

As per the previous posts the solution was only to add :

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
Intestate answered 6/6, 2018 at 15:6 Comment(0)
F
2

I had the very same exception but my spring-boot-starter-parent was version 1.3.3, as below

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.3.RELEASE</version>
</parent>

The exception showd up as I was upgrading to 1.4.1

The solution for me was

I had to lose the bad dependency:

<dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>2.1.4.RELEASE</version>
</dependency>

And replace it with the dependency below as per the Release notes of Spring Boot 1.4.0

 <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web-services</artifactId>          
 </dependency>
Fondafondant answered 28/10, 2016 at 0:6 Comment(0)
H
1

The problem for me was simply that I hadn't cleaned my project before running verify, after having made some significant changes.

Hypogeal answered 22/6, 2014 at 15:55 Comment(0)
S
0

I had a same problem with this error :

 Error creating bean with name 'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration': Initialization of bean failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy

I used below dependency in my POM.xml and the problem was solved :

 <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-spring-boot-autoconfigure -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-spring-boot-autoconfigure</artifactId>
        <version>3.2.1</version>
    </dependency>
Screwworm answered 18/8, 2019 at 14:16 Comment(0)
W
0

The solution approach of adding

spring-boot-starter-web-services

dependency, proposed in the above answers, is good, working, but excessive in cases where you don't need web context to be raised up. I mean, if your application doesn't wish to be a web application. In such a case, at least for me, the adding of the following thinner dependency also resolved the issue:

org.springframework:spring-webmvc

implementation 'org.springframework:spring-webmvc:5.2.1.RELEASE'

Whither answered 31/1, 2020 at 7:12 Comment(0)
P
0

If you are using spring JPA then make sure you have added the following dependency to pom.xml

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Plumley answered 21/9, 2020 at 8:41 Comment(0)
T
0

We ran into this issue when we were using an older version of Spring (1.x) and Websphere Liberty 22.0.0.3 with Java 8. The issue is no longer there with the latest WLP - 22.0.0.13.

Trichite answered 25/1, 2023 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.