title: a bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' that could not be found
body: <p>I want to use Spring Boot Security in my project by creating a simple login screen but i get these error even i define a bean for BCryptPassworrdEncoder. The full error is</p>
  
  <blockquote>
    <p><strong><em>Field bCryptPasswordEncoder in
    com.mahmut.demoemployee.application.dao.Imp.UserDaoImp required a bean
    of type
    'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder'
    that could not be found.</em></strong></p>
  </blockquote>
  
  <p>Here is my codes.</p>
  
  <pre><code>package com.mahmut.demoemployee.application.dao.Imp;
      //Some imports
  
              @Component
          public class UserDaoImp implements UserDao {
  
              @Autowired
              UserRepository userRepository;
  
              @Qualifier("roleRepository")
              @Autowired
              RoleRepository roleRepository;
  
              @Autowired
              private BCryptPasswordEncoder bCryptPasswordEncoder;
  
              @Override
              public User save(User user) {
                  user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
                  user.setActive(1);
                  Role userRole = roleRepository.findByRole("ADMIN");
                  user.setRoles(new HashSet&lt;Role&gt;(Arrays.asList(userRole)));
                  return userRepository.save(user);
              }
  
              @Override
              public User findUserByEmail(String email) {
                  return userRepository.findByEmail(email);
              }
  
              @Override
              public List&lt;User&gt; findAll() {
                  return (List&lt;User&gt;) userRepository.findAll();
              }
          }
  </code></pre>
  
  <p>And here is my config classes.</p>
  
  <pre><code>    package com.mahmut.demoemployee.application.config;
  
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  
  
  @Configuration
  public class WebMvcConfig extends WebSecurityConfigurerAdapter {
  
      @Bean
      public BCryptPasswordEncoder passwordEncoder() {
          BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
          return bCryptPasswordEncoder;
      }
  
  }
  </code></pre>
  
  <p>Security Config class</p>
  
  <pre><code> package com.mahmut.demoemployee.application.config;
  //Lots of import here
  
  @Configuration
  @EnableWebSecurity
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private BCryptPasswordEncoder bCryptPasswordEncoder;
  
      @Autowired
      private DataSource dataSource;
  
  
  
      @Value("${spring.queries.users-query}")
      private String usersQuery;
  
      @Value("${spring.queries.roles-query}")
      private String rolesQuery;
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth)
              throws Exception {
          auth.
                  jdbcAuthentication()
                  .usersByUsernameQuery(usersQuery)
                  .authoritiesByUsernameQuery(rolesQuery)
                  .dataSource(dataSource)
                  .passwordEncoder(bCryptPasswordEncoder);
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
  
          http.
                  authorizeRequests()
                  .antMatchers("/").permitAll()
                  .antMatchers("/login").permitAll()
                  .antMatchers("/registration").permitAll()
                  .antMatchers("/admin/**").hasAuthority("ADMIN").anyRequest()
                  .authenticated().and().csrf().disable().formLogin()
                  .loginPage("/login").failureUrl("/login?error=true")
                  .defaultSuccessUrl("/admin/home")
                  .usernameParameter("email")
                  .passwordParameter("password")
                  .and().logout()
                  .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                  .logoutSuccessUrl("/").and().exceptionHandling()
                  .accessDeniedPage("/access-denied");
      }
  
      @Override
      public void configure(WebSecurity web) throws Exception {
          web
                  .ignoring()
                  .antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**");
      }
  
  }
  </code></pre>
  
  <p>What i tried is;</p>
  
  <p><em>I tried to use <code>PasswordEncoder</code> instead of <code>BCryptPasswordEncoder</code> gives the same error with Password Encoder.
  I remove the <code>@Component</code> annotation and write <code>@Service</code> it gives same error as well.
  I dont know if its necessary but here is my pom.xml file. There are only essential dependencies.</em></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.mahmut&lt;/groupId&gt;
      &lt;artifactId&gt;demo-employee&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;demo-employee&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.0.3.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
              &lt;version&gt;2.0.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I dont know what else i could do. I checked lots of websites with similiar errors and did them but result is same. </p>