无法自省类 org.springframework.boot.web.servlet.support.SpringBootServletInitializer 上的注释方法

问题描述 投票:0回答:3

我有一个问题。当我尝试调试我的 springboot 应用程序时出现此错误,但出现以下错误

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.app.myapp.MyappApplication]; nested exception is java.lang.IllegalStateException:Failed to introspect annotated methods on class org.springframework.boot.web.servlet.support.SpringBootServletInitializer

我的

MyappApplication
班有以下

package com.app.myapp;
import java.io.File;
import java.nio.charset.Charset;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Date;

import javax.net.ssl.SSLContext;
import javax.servlet.ServletContext;

import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.ssl.TrustStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import com.app.myapp.model.Reponse;
import com.app.myapp.service.MyModel;

@SpringBootApplication
public class MyappApplication extends SpringBootServletInitializer implements 
CommandLineRunner {

@Autowired
ServletContext context;

@Autowired private MyModel myModel;
public static void main(String[] args) {
    ApplicationContext acx=SpringApplication.run(MyappApplication.class, args);
    String fileSeparator = File.separator;

}

@Override
public void run(String... args) throws Exception {
    
}
   /*
   @Bean
   public RestTemplate getRestTemplate() {
      return new RestTemplate();
   }*/
    @Bean
    public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
            TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
 
            SSLContext sslContext = SSLContexts.custom()
                            .loadTrustMaterial(null, acceptingTrustStrategy)
                            .build();
 
            SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
 
            CloseableHttpClient httpClient = HttpClients.custom()
                            .setSSLSocketFactory(csf)
                            .build();
 
            HttpComponentsClientHttpRequestFactory requestFactory =
                            new HttpComponentsClientHttpRequestFactory();
 
            requestFactory.setHttpClient(httpClient);
            RestTemplate restTemplate = new RestTemplate(requestFactory);
            return restTemplate;
    }      
 }

我的POM如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
   <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.1</version>
    <relativePath /> <!-- lookup parent from repository -->
   </parent>
   <groupId>com.app.myapp</groupId>
   <artifactId>myapp</artifactId>
   <version>0.0.1</version>
  <name>myApp</name>
  <description>Building software</description>
   <properties>
    <java.version>1.8</java.version>
   </properties>
   <dependencies>

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
         <!--           <scope>runtime</scope>-->
        <optional>true</optional>
    </dependency>

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

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.3</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>
   <dependency>
     <groupId>org.apache.httpcomponents</groupId>
     <artifactId>httpclient</artifactId>
  </dependency>

    <dependency>
        <groupId>nz.net.ultraq.thymeleaf</groupId>
        <artifactId>thymeleaf-layout-dialect</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<packaging>war</packaging>

可能是什么问题?

java spring spring-boot maven pom.xml
3个回答
5
投票

只有无效缓存对我没有帮助。请在 pom.xml 中检查您的 tomcat 的范围。有时范围是“提供”的,这就是它不编译类并抛出此错误的原因:

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

如果您在这里评论任何范围,请确保您重新启动系统,如果需要,也使索引缓存无效。这对我有用。


4
投票

我的问题是通过使缓存无效并重新启动我的 IDE 来解决的

谢谢


0
投票

我尝试了这篇文章中提供的两种解决方案:使缓存无效并删除了依赖范围。

在我删除范围(“提供”)后它对我有用。

请不要忘记在删除范围后重新加载 Maven 项目。

© www.soinside.com 2019 - 2024. All rights reserved.