【问题标题】:Spring boot error:java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy春季启动错误:java.lang.ArrayStoreException:sun.reflect.annotation.TypeNotPresentExceptionProxy
【发布时间】:2014-08-12 17:29:00
【问题描述】:

我想使用spring boot来启动我的应用程序,但是在pom.xml中添加了一些相关的jar之后,它返回了这个错误:谢谢可能是一些冲突jar引起的?

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 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)

主要问题:

 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>

登录控制器

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";
}
}

【问题讨论】:

标签: spring-mvc spring-boot


【解决方案1】:

如果您使用的是 spring JPA,请确保您已将以下依赖项添加到 pom.xml

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

【讨论】:

    【解决方案2】:

    添加的解决方法

    spring-boot-starter-web-services

    在上述答案中提出的依赖关系很好,可以工作,但在您不需要提出网络上下文的情况下过度。我的意思是,如果您的应用程序不希望成为 Web 应用程序。在这种情况下,至少对我来说,添加以下更薄的依赖项也解决了这个问题:

    org.springframework:spring-webmvc

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

    【讨论】:

      【解决方案3】:

      对我来说,问题只是在进行了一些重大更改之后,我没有在运行验证之前清理我的项目。

      【讨论】:

        【解决方案4】:

        这个错误我也有同样的问题:

         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
        

        我在我的 POM.xml 中使用了以下依赖项,问题已解决:

         <!-- 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>
        

        【讨论】:

          【解决方案5】:

          解决方案可能因实际不兼容的根本原因而异。如何调查此类问题的最佳方法是遵循以下路线:

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

          并将断点放入类'TypeNotPresentExceptionProxy'的构造函数中(只有一个)。

          在调试模式下执行后,您应该会看到究竟出了什么问题,并且根据您的发现,您可以决定要做什么(添加依赖项、排除 autoconfig,...)

          在我的具体情况下,断点揭示了这一点:

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

          作为解决方案,我决定像这样排除“IntegrationAutoConfiguration”:

          @SpringBootApplication(exclude = IntegrationAutoConfiguration.class)
          

          【讨论】:

          • 这实际上是您找到此类错误根本原因的方法。
          • @Jozef 我想将断点放入类 'TypeNotPresentExceptionProxy' 的构造函数中。但是当我尝试这样做时,我找不到 Source。我正在使用 Eclipse IDE。
          • @KarthikPai 试试这个stackoverflow.com/questions/6174550/…
          【解决方案6】:

          我遇到了同样的问题:

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

          根据之前的帖子,解决方案只是添加:

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

          【讨论】:

            【解决方案7】:

            我在 spring-boot-starter-parent 2.0.0.M6 上遇到了同样的问题。

            解决方案

            是删除

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

            并包含

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

            改为。

            【讨论】:

              【解决方案8】:

              正如 Andy Wilkinson 在 this GitHub issuethis thread 中所解释的,当某些注释引用不在类路径中的类时,会发生这些模糊的异常。

              大多数此类问题已在最近的 Spring Boot 版本中得到修复,但您也可以从代码中触发一个问题,例如在使用 @AutoConfigureAfter(X.class) 时,类路径中缺少类 X

              【讨论】:

              • 另外,检查github.com/spring-projects/spring-boot/issues/…。通过 TypeNotPresentExceptionProxy 中的断点,您可以发现缺少的类!
              • 谢谢伙计。这是最有用的答案。在那里设置断点给我发布类。
              • 感谢@Tobias,此链接和提示帮助我找出类路径中缺少的引用类。我没有 TypeNotPresentExceptionProxy 的源代码,但我能够使用 Eclipse 中的 Outline 视图设置断点 - 右键单击​​构造函数并切换断点。论据清楚地说明了罪魁祸首的名字。
              【解决方案9】:

              我也有同样的例外,但我的 spring-boot-starter-parent 是 1.3.3 版本,如下所示

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

              当我升级到 1.4.1 时出现异常

              我的解决方案是

              我不得不失去糟糕的依赖:

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

              并根据Release notes of Spring Boot 1.4.0 将其替换为下面的依赖项

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

              【讨论】:

                猜你喜欢
                • 2017-10-10
                • 2017-11-05
                • 1970-01-01
                • 2020-05-12
                • 1970-01-01
                • 1970-01-01
                • 2018-01-20
                • 1970-01-01
                相关资源
                最近更新 更多