简体   繁体   English

具有Spring Security的Spring Boot:创建名称为'securityConfiguration'的bean时出错

[英]Spring boot with spring security: Error creating bean with name 'securityConfiguration'

I'm building a web application for learning purpose. 我正在构建一个用于学习目的的Web应用程序。 But when tried to implement spring security, and running the application, I'm getting Error creating bean with name 'securityConfiguration' . 但是,当尝试实现spring security并运行应用程序时, 创建名称为'securityConfiguration'的bean时出现错误 After completing schema export, this error is showing in console. 完成架构导出后,此错误将显示在控制台中。

I have attached my build.gradle file, application.properties file, spring security configuration class and of course error logs too. 我已经附加了build.gradle文件, application.properties文件,spring安全配置类以及错误日志。

Tried through searching on this site too. 也通过在此站点上搜索进行了尝试。 But have not found anything relevant to my one. 但是还没有找到任何与我有关的东西。

build.gradle is: build.gradle是:

buildscript {
    ext {
        springBootVersion = '1.5.10.RELEASE'
    }
    repositories {

        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'

group = 'com.development'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {

    mavenLocal()
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'org.springframework.security:spring-security-web:5.0.3.RELEASE'
    compile group: 'org.springframework.security', name: 'spring-security-config', version: '5.0.3.RELEASE'

    compile 'org.webjars.bower:bootstrap:4.0.0-beta'
    compile 'org.webjars.bower:jquery:3.3.1'
    compile 'org.webjars.npm:popper.js:1.13.0'
    compile 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:1.4.0'
    compile 'mysql:mysql-connector-java:5.1.34'

    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

application.properties is: application.properties是:

# LOGGING
logging.file=onlineQuiz.log
logging.level.com.development.onlineQuiz=DEBUG

# THYMELEAF
spring.thymeleaf.cache=false

# DATASOURCE
spring.datasource.url=jdbc:mysql://localhost/onlinequiz
spring.datasource.username=root
spring.datasource.password=nopass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

# JPA
spring.jpa.properties.hibernate.globally_quoted_identifiers=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.data.jpa.repositories.enabled=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

My spring security configure class is : 我的春季安全配置类是:

package com.development.onlineQuiz.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {

        httpSecurity
                .csrf().disable()
                .authorizeRequests()
            //  .antMatchers("/index").permitAll()
                .antMatchers("/index").authenticated()
                .and()
                .formLogin()
                .usernameParameter("user")
                .passwordParameter("password")
                .defaultSuccessUrl("/home")
                .loginPage("/index");
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {

        auth.inMemoryAuthentication().withUser("Mukit").password("pass").roles("USER");
    }
}

And the error I'm getting is: 我得到的错误是:

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-03-24 20:37:05.923 ERROR 2060 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.accept.ContentNegotiationManager]: Factory method 'mvcContentNegotiationManager' threw exception; nested exception is java.lang.AbstractMethodError: org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration.configureContentNegotiation(Lorg/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer;)V
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:667) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at com.development.onlineQuiz.OnlineQuizApplication.main(OnlineQuizApplication.java:10) [bin/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.accept.ContentNegotiationManager]: Factory method 'mvcContentNegotiationManager' threw exception; nested exception is java.lang.AbstractMethodError: org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration.configureContentNegotiation(Lorg/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer;)V
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    ... 19 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.accept.ContentNegotiationManager]: Factory method 'mvcContentNegotiationManager' threw exception; nested exception is java.lang.AbstractMethodError: org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration.configureContentNegotiation(Lorg/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer;)V
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    ... 31 common frames omitted
Caused by: java.lang.AbstractMethodError: org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration.configureContentNegotiation(Lorg/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer;)V
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurerComposite.configureContentNegotiation(WebMvcConfigurerComposite.java:59) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration.configureContentNegotiation(DelegatingWebMvcConfiguration.java:62) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.mvcContentNegotiationManager(WebMvcConfigurationSupport.java:375) ~[spring-webmvc-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration.mvcContentNegotiationManager(WebMvcAutoConfiguration.java:465) ~[spring-boot-autoconfigure-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$8dc037ac.CGLIB$mvcContentNegotiationManager$1(<generated>) ~[spring-boot-autoconfigure-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$8dc037ac$$FastClassBySpringCGLIB$$62192ff4.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$8dc037ac.mvcContentNegotiationManager(<generated>) ~[spring-boot-autoconfigure-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    ... 32 common frames omitted

Spring Boot 1.5 is build around Spring Security 4.x however in your list of dependencies you have Spring Security 5 as a dependency. Spring Boot 1.5基于Spring Security 4.x构建,但是在依赖项列表中,您将Spring Security 5作为依赖项。 As you are using Spring Boot it is recommended to use the starters provided by Spring Boot, that way you get the version belonging to that version of Spring Boot. 当你使用Spring启动,建议使用由Spring提供引导起动器,这样你属于那个版本春天启动的版本。 So instead of adding dependencies on org.springframework.security projects use spring-boot-starter-security instead. 因此,不是在org.springframework.security项目上添加依赖项,而是使用spring-boot-starter-security

compile 'org.springframework.boot:spring-boot-starter-security'

暂无
暂无

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

相关问题 具有spring security的spring boot:创建名为&#39;securityFilterChainRegistration&#39;的bean时出错 - spring boot with spring security : Error creating bean with name 'securityFilterChainRegistration' Spring 引导错误创建名称为错误的 bean - Spring boot Error creating bean with name Error Spring Boot:创建名称为&#39;methodValidationPostProcessor&#39;的bean时出错 - Spring boot : Error creating bean with name 'methodValidationPostProcessor' Spring 安全性:创建名为 springsecurityfilterchain 的 bean 时出错 - Spring Security: error creating bean with name springsecurityfilterchain @WebMvcTest 创建名为“securityConfiguration”的 bean 时出错 - @WebMvcTest Error creating bean with name 'securityConfiguration' Spring Boot“使用名称创建bean时出错” - Spring Boot "Error creating bean with name" 创建名为“requestMappingHandlerAdapter”的 bean 时出错 Spring Boot - Error creating bean with name 'requestMappingHandlerAdapter' Spring Boot Spring Boot 错误创建名为“optionalLiveReloadServer”的bean - Spring Boot Error creating bean with name 'optionalLiveReloadServer' Spring Boot:创建名为“springSecurityFilterChain”的 bean 时出错 - Spring Boot: Error creating bean with name 'springSecurityFilterChain' Spring 引导:创建名为“persistenceExceptionTranslationPostProcessor”的 bean 时出错 - Spring boot : Error creating bean with name 'persistenceExceptionTranslationPostProcessor'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM