简体   繁体   English

找不到类型为[org.springframework.security.config.annotation.web.builders.HttpSecurity]的限定bean

[英]No qualifying bean of type [org.springframework.security.config.annotation.web.builders.HttpSecurity] found for dependency

I'm trying create java web application with Spring Security + Spring MVC. 我正在尝试使用Spring Security + Spring MVC创建java Web应用程序。 I go error: 我去了错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: protected void ggdb.SecurityConfiguration.configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) throws java.lang.Exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.web.builders.HttpSecurity] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1204)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: protected void ggdb.SecurityConfiguration.configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) throws java.lang.Exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.web.builders.HttpSecurity] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 22 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.web.builders.HttpSecurity] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:600)
    ... 24 more

My pom.xml: 我的pom.xml:

<properties>
    <spring.version>4.1.2.RELEASE</spring.version>
    <spring.security.version>3.2.5.RELEASE</spring.security.version>
    <javax.servlet.version>3.1.0</javax.servlet.version>
    <mysql.connector.version>5.1.34</mysql.connector.version>
    <hibernate.version>4.3.7.Final</hibernate.version>
    <commons.dbcp2.version>2.0.1</commons.dbcp2.version>
    <jstl.version>1.2</jstl.version>
</properties>

<build>
    <filters>
        <filter>filters/maven.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>${spring.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
        <version>${commons.dbcp2.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>4.3.7.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring.security.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
    </dependency>

My Initializer: 我的初始化程序:

public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[] { RootConfiguration.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[] {};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

}

My RootConfiguration: 我的RootConfiguration:

@Configuration
@ComponentScan
public class RootConfiguration {
}

and SecuriryConfiguration: 和SecuriryConfiguration:

@Configuration
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService userDetailsService;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }

    @Autowired
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .anyRequest()
                .permitAll();
    }

    public UserDetailsService getUserDetailsService() {
        return userDetailsService;
    }

    public void setUserDetailsService(UserDetailsService userDetailsService) {
        this.userDetailsService = userDetailsService;
    }
}

Could you tell me what is source of problem? 你能告诉我什么是问题的根源吗?

Try removing the @Autowired annotation of the configure(HttpSecurity http) method. 尝试删除configure(HttpSecurity http)方法的@Autowired注释。 The WebSecurityConfigurerAdapter should provide you with the HttpSecurity automatically. WebSecurityConfigurerAdapter应自动为您提供HttpSecurity。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoSuchBeanDefinitionException:没有可用的“org.springframework.security.config.annotation.web.builders.HttpSecurity”类型的合格 bean - NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' available Spring 引导:考虑在您的配置中定义类型为“org.springframework.security.config.annotation.web.builders.HttpSecurity”的 bean - Spring Boot : Consider defining a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' in your configuration spring 安全性:NoSuchBeanDefinitionException:找不到 [org.springframework.security.config.annotation.ObjectPostProcessor] 类型的合格 bean - spring security: NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.config.annotation.ObjectPostProcessor] found 没有 &#39;org.springframework.security.config.annotation.ObjectPostProcessor 类型的合格 bean<?> &#39; 当我使用 ContextHierarchy 时可用 - No qualifying bean of type 'org.springframework.security.config.annotation.ObjectPostProcessor<?>' available when I use ContextHierarchy 没有类型为&#39;org.springframework.security.authentication.AuthenticationProvider&#39;的合格Bean - No qualifying bean of type 'org.springframework.security.authentication.AuthenticationProvider' 没有“org.springframework.security.core.userdetails.UserDetailsService”类型的合格bean - No qualifying bean of type 'org.springframework.security.core.userdetails.UserDetailsService' Spring Neo4j:NoSuchBeanDefinitionException:找不到依赖项类型为[org.springframework.data.neo4j.support.Neo4jTemplate]的合格bean - Spring Neo4j: NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.neo4j.support.Neo4jTemplate] found for dependency NoSuchBeanDefinitionException:找不到依赖项类型为[org.hibernate.SessionFactory]的合格bean - NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.SessionFactory] found for dependency 找不到依赖项类型为[org.hibernate.SessionFactory]的合格Bean - No qualifying bean of type [org.hibernate.SessionFactory] found for dependency 找不到依赖类型的合格Bean - No qualifying bean of type found for dependency
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM