maven 无法内省类org.springframework.boot.web.servlet.support.SpringBootServletInitializer上的带注解的方法

4ngedf3f  于 2022-10-26  发布在  Maven
关注(0)|答案(2)|浏览(342)

我有个问题。当我尝试运行调试我的Sprringboot应用程序时,我遇到了这个错误,但我有以下错误

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>

这可能是什么问题?

mrwjdhj3

mrwjdhj31#

我的问题只需使缓存无效并重新启动IDE即可解决
谢谢

q8l4jmvw

q8l4jmvw2#

仅使缓存无效对我没有帮助。请在pom.xml中检查一下Tomcat的作用域。有时会“提供”Scope,这就是它不编译类并抛出以下错误的原因:

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

如果您在这里注解任何作用域,请确保重新启动系统,并在需要时也使索引的缓存无效。这对我很管用。

相关问题