Error creating bean named 'springSecurityFilterChain'

Asked

Viewed 337 times

-3

I am trying to use Spring Security, but the following error is occurring:

GRAVE: Exception to sending context event started for instance System class [org.springframework.web.context.Contextloaderlistener] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is java.lang.RuntimeException: Could not postProcess org.springframework.security.authentication.dao.DaoAuthenticationProvider@6ef11a53 of type class org.springframework.security.authentication.dao.DaoAuthenticationProvider at org.springframework.Beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(Constructorresolver.java:601) at org.springframework.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(Abstractautowirecapablebeanfactory.java:1113) at org.springframework.Beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(Abstractautowirecapablebeanfactory.java:1008) at org.springframework.Beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(Abstractautowirecapablebeanfactory.java:505) at org.springframework.Beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(Abstractautowirecapablenfactory.java:476) at org.springframework.Beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:302) 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.AbstractBeanFactory.doGetBean(Abstractbeanfactory.java:292) at org.springframework.Beans.factory.support.AbstractBeanFactory.getBean(Abstractbeanfactory.java:193) at org.springframework.Beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(Defaultlistablebeanfactory.java:725) 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.configuraeAndRefreshWebApplicationContext(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:4666) at org.apache.Catalina.core.Standardcontext.startInternal(Standardcontext.java:5136) at org.apache.Catalina.util.Lifecyclebase.start(Lifecyclebase.java:183) at org.apache.Catalina.core.Containerbase$Startchild.call(Containerbase.java:1377) at org.apache.Catalina.core.Containerbase$Startchild.call(Containerbase.java:1367) at java.util.Concurrent.FutureTask.run(Futuretask.java:266) at org.apache.Tomcat.util.threads.InlineExecutorService.execute(Inlineexecutorservice.java:75) at java.util.Concurrent.AbstractExecutorService.Submit(Abstractexecutorservice.java:134) at org.apache.Catalina.core.Containerbase.startInternal(Containerbase.java:902) at org.apache.Catalina.core.Standardhost.startInternal(Standardhost.java:831) at org.apache.Catalina.util.Lifecyclebase.start(Lifecyclebase.java:183) at org.apache.Catalina.core.Containerbase$Startchild.call(Containerbase.java:1377) at org.apache.Catalina.core.Containerbase$Startchild.call(Containerbase.java:1367) at java.util.Concurrent.FutureTask.run(Futuretask.java:266) at org.apache.Tomcat.util.threads.InlineExecutorService.execute(Inlineexecutorservice.java:75) at java.util.Concurrent.AbstractExecutorService.Submit(Abstractexecutorservice.java:134) at org.apache.Catalina.core.Containerbase.startInternal(Containerbase.java:902) at org.apache.Catalina.core.Standardengine.startInternal(Standardengine.java:262) at org.apache.Catalina.util.Lifecyclebase.start(Lifecyclebase.java:183) at org.apache.Catalina.core.Standardservice.startInternal(Standardservice.java:423) at org.apache.Catalina.util.Lifecyclebase.start(Lifecyclebase.java:183) at org.apache.Catalina.core.Standardserver.startInternal(Standardserver.java:928) at org.apache.Catalina.util.Lifecyclebase.start(Lifecyclebase.java:183) at org.apache.Catalina.startup.Catalina.start(Catalina.java:638) at sun.reflect.Nativemethodaccessorimpl.invoke0(Native Method) at sun.reflect..Nativemethodaccessorimpl.invoke(Nativemethodaccessorimpl.java:62) at sun.reflect.Delegatingmethodaccessorimpl.invoke(Delegatingmethodaccessorimpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.Catalina.startup.Bootstrap.start(Bootstrap.java:350) at org.apache.Catalina.startup.Bootstrap.main(Bootstrap.java:492) Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception; nested exception is java.lang.RuntimeException: Could not postProcess org.springframework.security.authentication.dao.DaoAuthenticationProvider@6ef11a53 of type class org.springframework.security.authentication.dao.DaoAuthenticationProvider org.springframework.Beans.factory.support.SimpleInstantiationStrategy.instantiate(Simpleinstantiationstrategy.java:188) at org.springframework.Beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(Constructorresolver.java:590) ... 46 more Caused by: java.lang.RuntimeException: Could not postProcess org.springframework.security.authentication.dao.DaoAuthenticationProvider@6ef11a53 of type class org.springframework.security.authentication.dao.DaoAuthenticationProvider at org.springframework.security.config.Annotation.configuration.Autowirebeanfactoryobjectpostprocessor.postProcess(Autowirebeanfactoryobjectpostprocessor.java:63) at org.springframework.security.config.Annotation.Securityconfigureradapter$Compositeobjectpostprocessor.postProcess(Securityconfigureradapter.java:117) at org.springframework.security.config.Annotation.SecurityConfigurerAdapter.postProcess(Securityconfigureradapter.java:77) at

pom.xml file:

<?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>
  <groupId>org.casadocodigo</groupId>
  <artifactId>casadocodigo</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <finalName>casadocodigo</finalName>
  </build>
  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-servlet-api</artifactId>
        <version>7.0.30</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>jstl-api</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion> 
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- Logging -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.6.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.1.0.RELEASE</version>
    </dependency>   
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.15</version>
    </dependency>   

    <!-- JSR 303 with Hibernate Validator -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.1.0.Final</version>
    </dependency>

    <!-- s3ninja -->
    <dependency>
        <groupId>com.scireum</groupId>
        <artifactId>s3ninja</artifactId>
        <version>2.3.2</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.11.133</version>
    </dependency>

    <!-- Jackson -->
    <!-- Jackson é um biblioteca para transformar objetos em JSON -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.5.1</version>        
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.1</version>
    </dependency>

    <!-- Cache -->

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.1.0.RELEASE</version>
    </dependency>

    <!-- Spring security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.0.0.M2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>4.0.0.M2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.0.0.M2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.0.0.M2</version>
    </dependency>

  </dependencies>
  <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>SPring Milestones</name>
            <url>http://repo.spring.io/milestones/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project

>
  • It seems you did not report any implementation of UserDetailsService, you have already created your implementation?

1 answer

0

You need to create a service that implements Userdetailsservice.

For example:

@Service
public class MyUserDetailsService implements UserDetailsService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) {
        User user = userRepository.findByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException(username);
        }
        return new MyUserPrincipal(user);
    }
}
public class MyUserPrincipal implements UserDetails {
    private User user;

    public MyUserPrincipal(User user) {
        this.user = user;
    }
    //...
}

Due to annotation @Service the application will detect Userdetailsservice during the Component-scan.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.