Guest User

Untitled

a guest
May 17th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. @Configuration
  2. @EnableWebMvc
  3. @EnableTransactionManagement
  4. @ComponentScan(basePackages = "com.project.shopping")
  5. public class ShoppingServletConfig {
  6. @Primary
  7. @Bean(name = "dataSource")
  8. public DataSource dataSource() {
  9. BasicDataSource dataSource = new BasicDataSource();
  10. dataSource.setDriverClassName("com.mysql.jdbc.Driver");
  11. dataSource.setUrl("jdbc:mysql://localhost:3306/shopping");
  12. dataSource.setUsername("root");
  13. dataSource.setPassword("root");
  14. return dataSource;
  15. }
  16.  
  17. }
  18.  
  19. @Configuration
  20. @EnableWebSecurity
  21.  
  22. public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
  23. @Autowired
  24. @Qualifier("dataSource")
  25. DataSource dataSource;
  26. @Autowired
  27. public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  28. auth
  29. .jdbcAuthentication()
  30. .dataSource(dataSource)
  31. .usersByUsernameQuery(
  32. "select username,password, enabled from user where user_name=?")
  33. .authoritiesByUsernameQuery(
  34. "select username, role from user_roles where user_name=?");
  35. }
  36.  
  37. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springSecurityConfig':
  38. Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=dataSource)}
  39.  
  40. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate.
  41. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=dataSource)}
Add Comment
Please, Sign In to add comment