簡體   English   中英

無法自省類 [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration]

[英]Failed to introspect Class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration]

我使用 spring boot 2.1.1 創建了一個項目,當我嘗試解除它時,我收到以下錯誤:

2018-12-10 19:23:14.837 錯誤 8096 --- [main] osboot.SpringApplication:應用程序運行失敗

java.lang.IllegalStateException: org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64) 的 org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer 上的錯誤處理條件~[spring-boot- autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在 org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.1.3.RELEASE.jar:5.1 .3.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:181) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在 org.springframework.context .annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.context.annotation.ConfigurationClassB eanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:327) ~ [spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在 org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232) ~[spring-context-5.1.3.RELEASE。 jar:5.1.3.RELEASE] 在 org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在 org. springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.context.support.AbstractApplication Context.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:691) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528) ~ [spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar:2.1 .1.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在 org.springframework.boot.SpringApplication。運行(SpringApplication.java:316)[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)[spring-boot-2.1 .1.RELEASE.jar:2.1.1.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在atuq.FrigorificoApplication.main(FrgorificoApplication.java:14) [類 s/:na] 原因:java.lang.IllegalStateException:無法從 org 的 ClassLoader [sun.misc.Launcher$AppClassLoader@73d16e93] 中自省類 [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration] .springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:686) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java: 583)~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:568)~[spring-core-5.1.3.RELEASE .jar:5.1.3.RELEASE] 在 org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:626) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在 java.util .concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_181] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapabl eBeanFactory.java:721)~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:662)~[spring -beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:630) ~[spring-beans-5.1.3.RELEASE. jar:5.1.3.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1518) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1023) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE] at org.springframework.boot.autoconfigure.condition .BeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:195) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.boot.autoconfigure .condition.BeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:159) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanType( BeanTypeRegistry.java:152) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.updateTypesIfNecessary(BeanTypeRegistry.java:140) ~ [spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_181] at org.springframework.boot .autoconfigure.condition.BeanTypeRegistry.updateTypesIfNecessary(BeanTypeRegistry.java:135) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在 org.springframework.boot.autoconfigure.condition.BeanTypeRegistry。 getNamesForType(BeanTypeRegistry.java:97) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectB eanNamesForType(OnBeanCondition.java:298) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:289 ) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:278) ~[spring-boot- autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] 在 org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:189) ~[spring-boot-autoconfigure-2.1.1.RELEASE .jar:2.1.1.RELEASE] 在 org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:160) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1. RELEASE] at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.1.1.RELEASE.jar:2.1.1.RELEASE] ... 16 常見幀省略原因 d by:java.lang.NoClassDefFoundError: java.lang.Class.getDeclaredMethods0(Native Method) 處的 javax/servlet/Filter ~[na:1.8.0_181] 處 java.lang.Class.privateGetDeclaredMethods(Class.java:2701) 處~ [na:1.8.0_181] 在 java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_181] 在 org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:668) ~[spring -core-5.1.3.RELEASE.jar:5.1.3.RELEASE] ... 省略了 38 個常見框架 原因:java.lang.ClassNotFoundException: javax.servlet.Filter at java.net.URLClassLoader.findClass(URLClassLoader.java :381) ~[na:1.8.0_181] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_181] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349 ) ~[na:1.8.0_181] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_181] ...省略了 42 個常用幀

paso el pom.xml:

    <?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.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>atuq</groupId>
    <artifactId>frigorifico</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>frigorifico</name>
    <description>Frigorifico Malargue</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.0</version>
            <type>jar</type>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
            <type>jar</type>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

如果您在 POM 中對 spring-boot-starter-tomcat 有以下依賴關系,請刪除它的范圍部分。

現存的:

<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-tomcat</artifactId>
</dependency>

該錯誤很有幫助,因為它找不到所需的類javax.servlet.Filter並且擁有此類的常用方法是通過此依賴項:

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

最終拉入org.apache.tomcat.embed:tomcat-embed-core

我們在本地看到了這一點,因為當從 Intellij 運行 Spring Boot 應用程序時,我們沒有在“運行/調試配置”中勾選“包含具有“已提供”范圍的依賴項”選項。

我認為這種依賴:

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

與此發生沖突:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <type>jar</type>
</dependency>

為什么需要最后一個? 我認為你不需要它,因為你已經有了安全啟動器,所以刪除它。

嘗試將此添加到您的 pom.xml:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>4.0.1.RELEASE</version>
</dependency>

它幫助了我。

這是在嘗試引用不存在的類時引起的。 添加此依賴項修復了我的錯誤:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
</dependency>

在我的日志底部出現了:

Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.security.servlet.SpringBootWebSecurityConfiguration$SecurityFilterChainConfiguration
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@73d16e93]
Caused by: java.lang.NoClassDefFoundError: org/springframework/security/web/SecurityFilterChain
Caused by: java.lang.ClassNotFoundException: org.springframework.security.web.SecurityFilterChain

顯示org.springframework.security.web.SecurityFilterChain類不存在。

所以在一些谷歌搜索中,我發現該類存在於spring-security-web存儲庫中。 將其添加到pom.xml中的依賴項后,瞧,下一次構建成功通過。

我今天遇到了同樣的問題。 事實證明,這個問題是由於主啟動類沒有放在代碼的最外層引起的。 確保您已在正確的位置定義了啟動類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 啟動 spring 引導時出錯 - 無法自省 Class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration] Oauth2 創建名為“org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration”的 bean 時出錯 class org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry 中的方法 requestMatchers<c> 不能應用於給定類型;</c> Spring 引導:考慮在您的配置中定義類型為“org.springframework.security.config.annotation.web.builders.HttpSecurity”的 bean org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer 中的 NullPointerException。<init></init> 找不到類型為[org.springframework.security.config.annotation.web.builders.HttpSecurity]的限定bean NoSuchBeanDefinitionException:沒有可用的“org.springframework.security.config.annotation.web.builders.HttpSecurity”類型的合格 bean 無法自省 Class [org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration spring 安全性:NoSuchBeanDefinitionException:找不到 [org.springframework.security.config.annotation.ObjectPostProcessor] 類型的合格 bean OAuth2:WebSecurityConfiguration 需要一個 'org.springframework.security.oauth2.client.registration.ClientRegistrationRepository' 類型的 bean
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM